datapath/dpdk: correct OVDK_VPORT_TYPE_MEMNIC

OVDK_VPORT_TYPE_MEMNIC has to point the next value from the last number of
OVDK_VPORT_TYPE_VETH vport.

Otherwise OVDK_VPORT_TYPE_MEMNIC, OVDK_VPORT_TYPE_VSWITCHD and
OVDK_VPORT_TYPE_DISABLED might be confused as VETH vport type.

Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Reviewed-by: Hayato Momma <h-momma@ce.jp.nec.com>
Tested-by: Mark D. Gray <mark.d.gray@intel.com>
vhost: Fix buffer overflow in writer port

When virtio device is down, tx_buf_count possibly overflows and
tx_buf are overwritten beyond its boundary.

This issue was found running FreeBSD, specifically BSDRP 1.52,
in VM.

Change-Id: I79814a1518591d92eb0a42ad7af208b1e6edd51a
Signed-off-by: Takayuki Usui <takayuki@midokura.com>
Tested-by: Mark D. Gray <mark.d.gray@intel.com>
veth: Reset tx buffer counter

All mbufs are just freed, so the counter should be reset as well.
Otherwise, mbuf possibly leaks and "bad ref cnt" error is going to
be reported from librte_mbuf.

Change-Id: Ief3cef338f7232890388dd51f0ff38b02f40d562
Signed-off-by: Takayuki Usui <takayuki@midokura.com>
Tested-by: Mark D. Gray <mark.d.gray@intel.com>
lib/dpif-dpdk: fix memory leak in upcall

valgrind detected memory leak in upcall.

==6318== 4,784 bytes in 46 blocks are definitely lost in loss record 403 of 415
==6318==    at 0x4C2845D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==6318==    by 0x4C7037: xmalloc (util.c:108)
==6318==    by 0x4AD4F4: ofpbuf_new_with_headroom (ofpbuf.c:140)
==6318==    by 0x4AD613: ofpbuf_clone_data (ofpbuf.c:209)
==6318==    by 0x4F167F: dpdk_link_recv_packet (dpdk-link.c:298)
==6318==    by 0x4E3FB2: dpif_dpdk_recv (dpif-dpdk.c:1676)
==6318==    by 0x471218: dpif_recv (dpif.c:1333)
==6318==    by 0x452C9C: udpif_dispatcher (ofproto-dpif-upcall.c:838)
==6318==    by 0x2539FDF2: start_thread (in /usr/lib64/libpthread-2.17.so)
==6318==    by 0x25DB801C: clone (in /usr/lib64/libc-2.17.so)

The 'buf' is declared in dpif_dpdk_recv() and newly allocated by
ofpbuf_clone_data(). Only the caller-provided 'buf' is freed,
while the declared 'buf' is not. This leads to memory leak.
The 'upcall->key' and 'upcall->userdata' should be the pointers to the
caller-provided 'buf' as specified for recv() in dpif-provider.h .

The following is the snippet of the specification of recv()
in dpif-provider.h,which was updated in commit 693eb1ff
(Squashed 'openvswitch/' changes from b254093..e8b77d8).
     * The implementation should point 'upcall->key' and 'upcall->userdata'
     * (if any) into data in the caller-provided 'buf'.  The implementation may
     * also use 'buf' for storing the data of 'upcall->packet'.  If necessary
     * to make room, the implementation may reallocate the data in 'buf'.

Also, upcall->packet and caller-provided 'buf' should not refer
to the same ofpbuf memory area, because both are freed in upcall_destroy()
and this leads to double free.

Change-Id: I50402455c296a68386fd711399fb957c5c8e50fc
Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Signed-off-by: Hiroaki Yamamoto <yamamoto.hrk@ncos.nec.co.jp>
Reviewed-by: Hayato Momma <h-momma@ce.jp.nec.com>
Tested-by: Mark D. Gray <mark.d.gray@intel.com>
datapath/dpdk: reduce the number of TX queues of phy port

Reduce the number of TX queues to the number of enabled lcores instead
of RTE_MAX_LCORE. Assign the TX queue to enabled lcore only, because
the TX queues for disabled lcores will never be used.
This makes the device which has small number of queues usable.

This will enable the use of NICs with a low number of queues.

Change-Id: If21642fa59cfee78faae12ef7be86ece8e6f362a
Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Reviewed-by: Hayato Momma <h-momma@ce.jp.nec.com>
Tested-by: Mark D. Gray <mark.d.gray@intel.com>