test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [RFC PATCH 0/8] support fm10k family nics
@ 2015-12-13  4:57 Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 1/8] framework settings: rename nic_name_from_type to get_nic_name Yong Liu
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Yong Liu @ 2015-12-13  4:57 UTC (permalink / raw)
  To: dts

fm10k family nics required addtional setup functions for testpoint. All
functions will be enabled after startup and configure testpoint. For some nics
like RubyRapid and BulderRapid, two ports will share one testpoint.

For clearify nic functions, created another folder named "nics" which will
contained all nic modules. 

Marvin Liu (8):
  framework settings: rename nic_name_from_type to get_nic_name
  framework crb: add function to retrieve port information
  framework: create independent foler for nic modules
  nics: add fm10k module for RedRockCanYou family nic
  framework: net device object get from net_device module
  framework dts: close netdevice related session after exit
  conf: add sample for RedRockCanYou family nic
  framework project_dpdk: add extra setup after bind driver

 conf/ports.cfg            |   6 +-
 framework/checkCase.py    |   4 +-
 framework/crb.py          |   8 +
 framework/dts.py          |  14 +-
 framework/dut.py          |  22 +-
 framework/main.py         |   6 +-
 framework/net_device.py   | 770 ------------------------------------------
 framework/project_dpdk.py |   9 +
 framework/settings.py     |   3 +-
 framework/test_case.py    |   4 +-
 framework/virt_dut.py     |   4 +-
 nics/fm10k.py             | 164 +++++++++
 nics/net_device.py        | 832 ++++++++++++++++++++++++++++++++++++++++++++++
 13 files changed, 1047 insertions(+), 799 deletions(-)
 delete mode 100644 framework/net_device.py
 create mode 100644 nics/fm10k.py
 create mode 100644 nics/net_device.py

-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dts] [PATCH 1/8] framework settings: rename nic_name_from_type to get_nic_name
  2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
@ 2015-12-13  4:57 ` Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 2/8] framework crb: add function to retrieve port information Yong Liu
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yong Liu @ 2015-12-13  4:57 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

This function will return nic name by pci type.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/checkCase.py b/framework/checkCase.py
index e7b22f1..94e6a4a 100644
--- a/framework/checkCase.py
+++ b/framework/checkCase.py
@@ -1,6 +1,6 @@
 import xlrd
 
-from settings import nic_name_from_type
+from settings import get_nic_name
 
 filter_file = r'./conf/dpdk_test_case_checklist.xls'
 filter_case = []
@@ -96,7 +96,7 @@ class check_case_skip():
     def check_nic(self, nic_type):
         if 'all' == nic_type[0].lower():
             return True
-        dut_nic_type = nic_name_from_type(self.dut.ports_info[0]['type'])
+        dut_nic_type = get_nic_name(self.dut.ports_info[0]['type'])
         if dut_nic_type in nic_type:
             return True
         else:
diff --git a/framework/settings.py b/framework/settings.py
index c99dcaa..0b658f2 100644
--- a/framework/settings.py
+++ b/framework/settings.py
@@ -40,6 +40,7 @@ FOLDERS = {
     'Configuration': 'conf',
     'Depends': 'dep',
     'Output': 'output',
+    'NicDriver': 'nics',
 }
 
 """
@@ -159,7 +160,7 @@ The log name seperater.
 LOG_NAME_SEP = '.'
 
 
-def nic_name_from_type(type):
+def get_nic_name(type):
     """
     strip nic code name by nic type
     """
diff --git a/framework/test_case.py b/framework/test_case.py
index 5013123..f601381 100644
--- a/framework/test_case.py
+++ b/framework/test_case.py
@@ -35,7 +35,7 @@ A base class for creating DTF test cases.
 
 import dts
 from exception import VerifyFailure
-from settings import DRIVERS, NICS, nic_name_from_type
+from settings import DRIVERS, NICS, get_nic_name
 
 
 class TestCase(object):
@@ -48,7 +48,7 @@ class TestCase(object):
         self.nics = []
         for portid in range(len(self.dut.ports_info)):
             nic_type = self.dut.ports_info[portid]['type']
-            self.nics.append(nic_name_from_type(nic_type))
+            self.nics.append(get_nic_name(nic_type))
         if len(self.nics):
             self.nic = self.nics[0]
         else:
-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dts] [PATCH 2/8] framework crb: add function to retrieve port information
  2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 1/8] framework settings: rename nic_name_from_type to get_nic_name Yong Liu
@ 2015-12-13  4:57 ` Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 3/8] framework: create independent foler for nic modules Yong Liu
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yong Liu @ 2015-12-13  4:57 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Add new function will retrieve port information based on pci address.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/crb.py b/framework/crb.py
index 9377565..525d6a1 100644
--- a/framework/crb.py
+++ b/framework/crb.py
@@ -689,3 +689,11 @@ class Crb(object):
             perCorelCs = [_ for _ in perSocklCs if _['core'] == coreNum]
 
             return perCorelCs[threadid]['thread']
+
+    def get_port_info(self, pci):
+        """
+        return port info by pci id
+        """
+        for port_info in self.ports_info:
+            if port_info['pci'] == pci:
+                return port_info
-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dts] [PATCH 3/8] framework: create independent foler for nic modules
  2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 1/8] framework settings: rename nic_name_from_type to get_nic_name Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 2/8] framework crb: add function to retrieve port information Yong Liu
@ 2015-12-13  4:57 ` Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 4/8] nics: add fm10k module for RedRockCanYou family nic Yong Liu
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yong Liu @ 2015-12-13  4:57 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Add nics module will be placed in "nics" folder, this folder is placed in the
same level of "frame" and "tests".
Net device object will be retrieved by GetNicObj function. Netdevice module
will handle the list of network device, netdevice object will only be
initialized once when running dts.
Netdevice module will define those function all nics should support. Sepcified
function will be defined in nic's own module.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/main.py b/framework/main.py
index de49e82..0760c95 100755
--- a/framework/main.py
+++ b/framework/main.py
@@ -37,11 +37,15 @@ A test framework for testing DPDK.
 import os
 import sys
 import argparse
-import dts
 
 # change operation directory
 os.chdir("../")
+cwd = os.getcwd()
+sys.path.append(cwd + '/nics')
+sys.path.append(cwd + '/framework')
+sys.path.append(cwd + '/tests')
 
+import dts
 
 def git_build_package(gitLabel, pkgName, depot="dep"):
     """
diff --git a/framework/net_device.py b/framework/net_device.py
deleted file mode 100644
index 37495bd..0000000
--- a/framework/net_device.py
+++ /dev/null
@@ -1,770 +0,0 @@
-# BSD LICENSE
-#
-# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-#   * Redistributions of source code must retain the above copyright
-#     notice, this list of conditions and the following disclaimer.
-#   * Redistributions in binary form must reproduce the above copyright
-#     notice, this list of conditions and the following disclaimer in
-#     the documentation and/or other materials provided with the
-#     distribution.
-#   * Neither the name of Intel Corporation nor the names of its
-#     contributors may be used to endorse or promote products derived
-#     from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-import os
-import re
-from functools import wraps
-import time
-
-
-import settings
-from crb import Crb
-from settings import TIMEOUT
-
-
-class NetDevice(object):
-
-    """
-    Abstract the device which is PF or VF.
-    """
-
-    def __init__(self, crb, bus_id, devfun_id):
-        if not isinstance(crb, Crb):
-            raise Exception("  Please input the instance of Crb!!!")
-        self.crb = crb
-        self.bus_id = bus_id
-        self.devfun_id = devfun_id
-        self.pci = bus_id + ':' + devfun_id
-        self.pci_id = self.get_pci_id(bus_id, devfun_id)
-        self.default_driver = settings.get_nic_driver(self.pci_id)
-
-        if self.nic_is_pf():
-            self.default_vf_driver = ''
-        self.get_interface_name()
-        self.socket = self.get_nic_socket()
-
-    def __send_expect(self, cmds, expected, timeout=TIMEOUT, alt_session=True):
-        """
-        Wrap the crb`s session as private session for sending expect.
-        """
-        return self.crb.send_expect(cmds, expected, timeout=timeout, alt_session=alt_session)
-
-    def __get_os_type(self):
-        """
-        Get OS type.
-        """
-        return self.crb.get_os_type()
-
-    def nic_is_pf(self):
-        """
-        It is the method that you can check if the nic is PF.
-        """
-        return True
-
-    def nic_has_driver(func):
-        """
-        Check if the NIC has a driver.
-        """
-        @wraps(func)
-        def wrapper(*args, **kwargs):
-            nic_instance = args[0]
-            nic_instance.current_driver = nic_instance.get_nic_driver()
-            if not nic_instance.current_driver:
-                return ''
-            return func(*args, **kwargs)
-        return wrapper
-
-    def get_nic_driver(self):
-        """
-        Get the NIC driver.
-        """
-        return self.crb.get_pci_dev_driver(self.bus_id, self.devfun_id)
-
-    def get_nic_socket(self):
-        """
-        Get socket id of specified pci device.
-        """
-        get_nic_socket = getattr(
-            self, 'get_nic_socket_%s' %
-            self.__get_os_type())
-        return get_nic_socket(self.bus_id, self.devfun_id)
-
-    def get_nic_socket_linux(self, bus_id, devfun_id):
-        command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/numa_node' %
-                   (bus_id, devfun_id))
-        try:
-            out = self.__send_expect(command, '# ')
-            socket = int(out)
-        except:
-            socket = -1
-        return socket
-
-    def get_nic_socket_freebsd(self, bus_id, devfun_id):
-        NotImplemented
-
-    @nic_has_driver
-    def get_interface_name(self):
-        """
-        Get interface name of specified pci device.
-        Cal this function will update intf_name everytime
-        """
-        get_interface_name = getattr(
-            self, 'get_interface_name_%s' %
-            self.__get_os_type())
-        out = get_interface_name(self.bus_id, self.devfun_id, self.current_driver)
-        if "No such file or directory" in out:
-            self.intf_name = 'N/A'
-        else:
-            self.intf_name = out
-
-        return self.intf_name
-
-    def get_interface_name_linux(self, bus_id, devfun_id, driver):
-        """
-        Get interface name of specified pci device on linux.
-        """
-        driver_alias = driver.replace('-', '_')
-        try:
-            get_interface_name_linux = getattr(
-                self,
-                'get_interface_name_linux_%s' %
-                driver_alias)
-        except Exception as e:
-            generic_driver = 'generic'
-            get_interface_name_linux = getattr(self,
-                                               'get_interface_name_linux_%s' % generic_driver)
-
-        return get_interface_name_linux(bus_id, devfun_id)
-
-    def get_interface_name_linux_virtio_pci(self, bus_id, devfun_id):
-        """
-        Get virtio device interface name by the default way on linux.
-        """
-        command = 'ls --color=never /sys/bus/pci/devices/0000\:%s\:%s/virtio*/net' % (
-            bus_id, devfun_id)
-        return self.__send_expect(command, '# ')
-
-    def get_interface_name_linux_generic(self, bus_id, devfun_id):
-        """
-        Get the interface name by the default way on linux.
-        """
-        command = 'ls --color=never /sys/bus/pci/devices/0000\:%s\:%s/net' % (
-            bus_id, devfun_id)
-        return self.__send_expect(command, '# ')
-
-    def get_interface_name_freebsd(self, bus_id, devfun_id, driver):
-        """
-        Get interface name of specified pci device on Freebsd.
-        """
-        try:
-            get_interface_name_freebsd = getattr(self,
-                                                 'get_interface_name_freebsd_%s' % driver)
-        except Exception as e:
-            generic_driver = 'generic'
-            get_interface_name_freebsd = getattr(self,
-                                                 'get_interface_name_freebsd_%s' % generic_driver)
-
-        return get_interface_name_freebsd(bus_id, devfun_id)
-
-    def get_interface_name_freebsd_generic(self, bus_id, devfun_id):
-        """
-        Get the interface name by the default way on freebsd.
-        """
-        out = self.__send_expect("pciconf -l", "# ")
-        rexp = r"(\w*)@pci0:%s" % bus_id
-        pattern = re.compile(rexp)
-        match = pattern.findall(out)
-        if len(match) == 0:
-            return "No such file"
-        return match[0]
-
-    @nic_has_driver
-    def set_vf_mac_addr(self, vf_idx=0, mac="00:00:00:00:00:01"):
-        """
-        Set mac address of specified vf device.
-        """
-        set_vf_mac_addr = getattr(self, 'set_vf_mac_addr_%s' % self.__get_os_type())
-        out = set_vf_mac_addr(self.intf_name, vf_idx, mac)
-
-    def set_vf_mac_addr_linux(self, intf, vf_idx, mac):
-        """
-        Set mac address of specified vf device on linux.
-        """
-        if self.current_driver != self.default_driver:
-            print "Only support when PF bound to default driver"
-            return
-
-        self.__send_expect("ip link set %s vf %d mac %s" % (intf, vf_idx, mac), "# ")
-
-    @nic_has_driver
-    def get_mac_addr(self):
-        """
-        Get mac address of specified pci device.
-        """
-        get_mac_addr = getattr(self, 'get_mac_addr_%s' % self.__get_os_type())
-        out = get_mac_addr(self.intf_name, self.bus_id, self.devfun_id, self.current_driver)
-        if "No such file or directory" in out:
-            return 'N/A'
-        else:
-            return out
-
-    def get_mac_addr_linux(self, intf, bus_id, devfun_id, driver):
-        """
-        Get mac address of specified pci device on linux.
-        """
-        driver_alias = driver.replace('-', '_')
-        try:
-            get_mac_addr_linux = getattr(
-                self,
-                'get_mac_addr_linux_%s' %
-                driver_alias)
-        except Exception as e:
-            generic_driver = 'generic'
-            get_mac_addr_linux = getattr(
-                self,
-                'get_mac_addr_linux_%s' %
-                generic_driver)
-
-        return get_mac_addr_linux(intf, bus_id, devfun_id, driver)
-
-    def get_pci_id(self, bus_id, devfun_id):
-        command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/vendor' %
-                   (bus_id, devfun_id))
-        out = self.__send_expect(command, '# ')
-        vender = out[2:]
-        command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/device' %
-                   (bus_id, devfun_id))
-        out = self.__send_expect(command, '# ')
-        device = out[2:]
-        return "%s:%s" % (vender, device)
-
-    def get_mac_addr_linux_generic(self, intf, bus_id, devfun_id, driver):
-        """
-        Get MAC by the default way on linux.
-        """
-        command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/net/%s/address' %
-                   (bus_id, devfun_id, intf))
-        return self.__send_expect(command, '# ')
-
-    def get_mac_addr_linux_virtio_pci(self, intf, bus_id, devfun_id, driver):
-        """
-        Get MAC by the default way on linux.
-        """
-        virtio_cmd = ('ls /sys/bus/pci/devices/0000\:%s\:%s/ | grep --color=never virtio' %
-                      (bus_id, devfun_id))
-        virtio = self.__send_expect(virtio_cmd, '# ')
-
-        command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/%s/net/%s/address' %
-                   (bus_id, devfun_id, virtio, intf))
-        return self.__send_expect(command, '# ')
-
-    def get_mac_addr_freebsd(self, intf, bus_id, devfun_id, driver):
-        """
-        Get mac address of specified pci device on Freebsd.
-        """
-        try:
-            get_mac_addr_freebsd = getattr(
-                self,
-                'get_mac_addr_freebsd_%s' %
-                driver)
-        except Exception as e:
-            generic_driver = 'generic'
-            get_mac_addr_freebsd = getattr(
-                self,
-                'get_mac_addr_freebsd_%s' %
-                generic_driver)
-
-        return get_mac_addr_freebsd(intf, bus_id, devfun_id)
-
-    def get_mac_addr_freebsd_generic(self, intf, bus_id, devfun_id):
-        """
-        Get the MAC by the default way on Freebsd.
-        """
-        out = self.__send_expect('ifconfig %s' % intf, '# ')
-        rexp = r"ether ([\da-f:]*)"
-        pattern = re.compile(rexp)
-        match = pattern.findall(out)
-        return match[0]
-
-    @nic_has_driver
-    def get_ipv4_addr(self):
-        """
-        Get ipv4 address of specified pci device.
-        """
-        get_ipv4_addr = getattr(
-            self, 'get_ipv4_addr_%s' % self.__get_os_type())
-        return get_ipv4_addr(self.intf_name, self.currenct_driver)
-
-    def get_ipv4_addr_linux(self, intf, driver):
-        """
-        Get ipv4 address of specified pci device on linux.
-        """
-        try:
-            get_ipv4_addr_linux = getattr(self, 'get_ipv4_linux_%s' % driver)
-        except Exception as e:
-            generic_driver = 'generic'
-            get_ipv4_addr_linux = getattr(
-                self, 'get_ipv4_linux_%s' %
-                generic_driver)
-
-        return get_ipv4_addr_linux(intf, bus_id, devfun_id, driver)
-
-    def get_ipv4_addr_linux_generic(self, intf):
-        """
-        Get IPv4 address by the default way on linux.
-        """
-        out = self.__send_expect("ip -family inet address show dev %s | awk '/inet/ { print $2 }'"
-                                 % intf, "# ")
-        return out.split('/')[0]
-
-    def get_ipv4_addr_freebsd(self, intf, driver):
-        """
-        Get ipv4 address of specified pci device on Freebsd.
-        """
-        try:
-            get_ipv4_addr_freebsd = getattr(
-                self,
-                'get_ipv4_addr_freebsd_%s' %
-                driver)
-        except Exception as e:
-            generic_driver = 'generic'
-            get_ipv4_addr_freebsd = getattr(
-                self,
-                'get_ipv4_addr_freebsd_%s' %
-                generic_driver)
-
-        return get_ipv4_addr_freebsd(intf, bus_id, devfun_id)
-
-    def get_ipv4_addr_freebsd_generic(self, intf):
-        """
-        Get the IPv4 address by the default way on Freebsd.
-        """
-        out = self.__send_expect('ifconfig %s' % intf, '# ')
-        rexp = r"inet ([\d:]*)%"
-        pattern = re.compile(rexp)
-        match = pattern.findall(out)
-        if len(match) == 0:
-            return None
-
-        return match[0]
-
-    @nic_has_driver
-    def enable_ipv6(self):
-        """
-        Enable ipv6 address of specified pci device.
-        """
-        if self.current_driver != self.default_driver:
-            return
-
-        enable_ipv6 = getattr(
-            self, 'enable_ipv6_%s' % self.__get_os_type())
-        return enable_ipv6(self.intf_name)
-
-    def enable_ipv6_linux(self, intf):
-        """
-        Enable ipv6 address of specified pci device on linux.
-        """
-        self.__send_expect("sysctl net.ipv6.conf.%s.disable_ipv6=0" %
-                           intf, "# ")
-        # FVL interface need down and up for re-enable ipv6
-        if self.default_driver == 'i40e':
-            self.__send_expect("ifconfig %s down" % intf, "# ")
-            self.__send_expect("ifconfig %s up" % intf, "# ")
-
-    def enable_ipv6_freebsd(self, intf):
-        pass
-
-    @nic_has_driver
-    def disable_ipv6(self):
-        """
-        Disable ipv6 address of specified pci device.
-        """
-        if self.current_driver != self.default_driver:
-            return
-        disable_ipv6 = getattr(
-            self, 'disable_ipv6_%s' % self.__get_os_type())
-        return disable_ipv6(self.intf_name)
-
-    def disable_ipv6_linux(self, intf):
-        """
-        Disable ipv6 address of specified pci device on linux.
-        """
-        self.__send_expect("sysctl net.ipv6.conf.%s.disable_ipv6=1" %
-                           intf, "# ")
-
-    def disable_ipv6_freebsd(self, intf):
-        pass
-
-    @nic_has_driver
-    def get_ipv6_addr(self):
-        """
-        Get ipv6 address of specified pci device.
-        """
-        get_ipv6_addr = getattr(
-            self, 'get_ipv6_addr_%s' % self.__get_os_type())
-        return get_ipv6_addr(self.intf_name, self.current_driver)
-
-    @nic_has_driver
-    def get_ipv6_addr(self):
-        """
-        Get ipv6 address of specified pci device.
-        """
-        get_ipv6_addr = getattr(
-            self, 'get_ipv6_addr_%s' % self.__get_os_type())
-        return get_ipv6_addr(self.intf_name, self.current_driver)
-
-    def get_ipv6_addr_linux(self, intf, driver):
-        """
-        Get ipv6 address of specified pci device on linux.
-        """
-        try:
-            get_ipv6_addr_linux = getattr(
-                self,
-                'get_ipv6_addr_linux_%s' %
-                driver)
-        except Exception as e:
-            generic_driver = 'generic'
-            get_ipv6_addr_linux = getattr(
-                self,
-                'get_ipv6_addr_linux_%s' %
-                generic_driver)
-
-        return get_ipv6_addr_linux(intf)
-
-    def get_ipv6_addr_linux_generic(self, intf):
-        """
-        Get the IPv6 address by the default way on linux.
-        """
-        out = self.__send_expect("ip -family inet6 address show dev %s | awk '/inet6/ { print $2 }'"
-                                 % intf, "# ")
-        return out.split('/')[0]
-
-    def get_ipv6_addr_freebsd(self, intf, driver):
-        """
-        Get ipv6 address of specified pci device on Freebsd.
-        """
-        try:
-            get_ipv6_addr_freebsd = getattr(
-                self,
-                'get_ipv6_addr_freebsd_%s' %
-                driver)
-        except Exception as e:
-            generic_driver = 'generic'
-            get_ipv6_addr_freebsd = getattr(
-                self,
-                'get_ipv6_addr_freebsd_%s' %
-                generic_driver)
-
-        return get_ipv6_addr_freebsd(intf)
-
-    def get_ipv6_addr_freebsd_generic(self, intf):
-        """
-        Get the IPv6 address by the default way on Freebsd.
-        """
-        out = self.__send_expect('ifconfig %s' % intf, '# ')
-        rexp = r"inet6 ([\da-f:]*)%"
-        pattern = re.compile(rexp)
-        match = pattern.findall(out)
-        if len(match) == 0:
-            return None
-
-        return match[0]
-
-    def get_nic_numa(self):
-        """
-        Get numa number of specified pci device.
-        """
-        self.crb.get_nic_numa(self.bus_id, self.devfun_id)
-
-    def get_card_type(self):
-        """
-        Get card type of specified pci device.
-        """
-        return self.crb.get_pci_dev_id(self.bus_id, self.devfun_id)
-
-    @nic_has_driver
-    def get_sriov_vfs_pci(self):
-        """
-        Get all SRIOV VF pci bus of specified pci device.
-        """
-        get_sriov_vfs_pci = getattr(
-            self, 'get_sriov_vfs_pci_%s' % self.__get_os_type())
-        return get_sriov_vfs_pci(self.bus_id, self.devfun_id, self.current_driver)
-
-    def get_sriov_vfs_pci_linux(self, bus_id, devfun_id, driver):
-        """
-        Get all SRIOV VF pci bus of specified pci device on linux.
-        """
-        try:
-            get_sriov_vfs_pci_linux = getattr(
-                self,
-                'get_sriov_vfs_pci_linux_%s' %
-                driver)
-        except Exception as e:
-            generic_driver = 'generic'
-            get_sriov_vfs_pci_linux = getattr(
-                self,
-                'get_sriov_vfs_pci_linux_%s' %
-                generic_driver)
-
-        return get_sriov_vfs_pci_linux(bus_id, devfun_id)
-
-    def get_sriov_vfs_pci_linux_generic(self, bus_id, devfun_id):
-        """
-        Get all the VF PCIs of specified PF by the default way on linux.
-        """
-        sriov_numvfs = self.__send_expect(
-            "cat /sys/bus/pci/devices/0000\:%s\:%s/sriov_numvfs" %
-            (bus_id, devfun_id), "# ")
-        sriov_vfs_pci = []
-
-        if "No such file" in sriov_numvfs:
-            return sriov_vfs_pci
-
-        if int(sriov_numvfs) == 0:
-            pass
-        else:
-            try:
-                virtfns = self.__send_expect(
-                    "ls -d /sys/bus/pci/devices/0000\:%s\:%s/virtfn*" %
-                    (bus_id, devfun_id), "# ")
-                for virtfn in virtfns.split():
-                    vf_uevent = self.__send_expect(
-                        "cat %s" %
-                        os.path.join(virtfn, "uevent"), "# ")
-                    vf_pci = re.search(
-                        r"PCI_SLOT_NAME=0000:([0-9a-f]+:[0-9a-f]+\.[0-9a-f]+)",
-                        vf_uevent).group(1)
-                    sriov_vfs_pci.append(vf_pci)
-            except Exception as e:
-                print "Scan linux port [0000:%s.%s] sriov vf failed: %s" % (bus_id, devfun_id, e)
-
-        return sriov_vfs_pci
-
-    @nic_has_driver
-    def generate_sriov_vfs(self, vf_num):
-        """
-        Generate some numbers of SRIOV VF.
-        """
-        if vf_num == 0:
-            self.bind_vf_driver()
-        generate_sriov_vfs = getattr(
-            self, 'generate_sriov_vfs_%s' %
-            self.__get_os_type())
-        generate_sriov_vfs(
-            self.bus_id,
-            self.devfun_id,
-            vf_num,
-            self.current_driver)
-        if vf_num != 0:
-            self.sriov_vfs_pci = self.get_sriov_vfs_pci()
-
-            vf_pci = self.sriov_vfs_pci[0]
-            addr_array = vf_pci.split(':')
-            bus_id = addr_array[0]
-            devfun_id = addr_array[1]
-
-            self.default_vf_driver = self.crb.get_pci_dev_driver(
-                bus_id, devfun_id)
-        else:
-            self.sriov_vfs_pci = []
-        time.sleep(1)
-
-    def generate_sriov_vfs_linux(self, bus_id, devfun_id, vf_num, driver):
-        """
-        Generate some numbers of SRIOV VF.
-        """
-        try:
-            generate_sriov_vfs_linux = getattr(
-                self,
-                'generate_sriov_vfs_linux_%s' %
-                driver)
-        except Exception as e:
-            generic_driver = 'generic'
-            generate_sriov_vfs_linux = getattr(
-                self,
-                'generate_sriov_vfs_linux_%s' %
-                generic_driver)
-
-        return generate_sriov_vfs_linux(bus_id, devfun_id, vf_num)
-
-    def generate_sriov_vfs_linux_generic(self, bus_id, devfun_id, vf_num):
-        """
-        Generate SRIOV VFs by the default way on linux.
-        """
-        nic_driver = self.get_nic_driver()
-
-        if not nic_driver:
-            return None
-
-        vf_reg_file = "sriov_numvfs"
-        vf_reg_path = os.path.join("/sys/bus/pci/devices/0000:%s:%s" %
-                                   (bus_id, devfun_id), vf_reg_file)
-        self.__send_expect("echo %d > %s" %
-                           (int(vf_num), vf_reg_path), "# ")
-
-    def generate_sriov_vfs_linux_igb_uio(self, bus_id, devfun_id, vf_num):
-        """
-        Generate SRIOV VFs by the special way of igb_uio driver on linux.
-        """
-        nic_driver = self.get_nic_driver()
-
-        if not nic_driver:
-            return None
-
-        vf_reg_file = "max_vfs"
-        if self.default_driver == 'i40e':
-            regx_reg_path = "find /sys -name %s | grep %s:%s" % (vf_reg_file, bus_id, devfun_id)
-            vf_reg_path = self.__send_expect(regx_reg_path, "# ")
-        else:
-            vf_reg_path = os.path.join("/sys/bus/pci/devices/0000:%s:%s" %
-                                       (bus_id, devfun_id), vf_reg_file)
-        self.__send_expect("echo %d > %s" %
-                           (int(vf_num), vf_reg_path), "# ")
-
-    def destroy_sriov_vfs(self):
-        """
-        Destroy the SRIOV VFs.
-        """
-        self.generate_sriov_vfs(0)
-
-    def bind_vf_driver(self, pci='', driver=''):
-        """
-        Bind the specified driver to VF.
-        """
-        bind_vf_driver = getattr(self, 'bind_driver_%s' % self.__get_os_type())
-        if not driver:
-            if not self.default_vf_driver:
-                print "Must specify a driver because default VF driver is NULL!"
-                return
-            driver = self.default_vf_driver
-
-        if not pci:
-            if not self.sriov_vfs_pci:
-                print "No VFs on the nic [%s]!" % self.pci
-                return
-            for vf_pci in self.sriov_vfs_pci:
-                addr_array = vf_pci.split(':')
-                bus_id = addr_array[0]
-                devfun_id = addr_array[1]
-
-                bind_vf_driver(bus_id, devfun_id, driver)
-        else:
-            addr_array = pci.split(':')
-            bus_id = addr_array[0]
-            devfun_id = addr_array[1]
-
-            bind_vf_driver(bus_id, devfun_id, driver)
-
-    def bind_driver(self, driver=''):
-        """
-        Bind specified driver to PF.
-        """
-        bind_driver = getattr(self, 'bind_driver_%s' % self.__get_os_type())
-        if not driver:
-            if not self.default_driver:
-                print "Must specify a driver because default driver is NULL!"
-                return
-            driver = self.default_driver
-        ret = bind_driver(self.bus_id, self.devfun_id, driver)
-        time.sleep(1)
-        return ret
-
-    def bind_driver_linux(self, bus_id, devfun_id, driver):
-        """
-        Bind NIC port to specified driver on linux.
-        """
-        driver_alias = driver.replace('-', '_')
-        try:
-            bind_driver_linux = getattr(
-                self,
-                'bind_driver_linux_%s' %
-                driver_alias)
-            return bind_driver_linux(bus_id, devfun_id)
-        except Exception as e:
-            driver_alias = 'generic'
-            bind_driver_linux = getattr(
-                self,
-                'bind_driver_linux_%s' %
-                driver_alias)
-            return bind_driver_linux(bus_id, devfun_id, driver)
-
-    def bind_driver_linux_generic(self, bus_id, devfun_id, driver):
-        """
-        Bind NIC port to specified driver by the default way on linux.
-        """
-        new_id = self.pci_id.replace(':', ' ')
-        nic_pci_num = ':'.join(['0000', bus_id, devfun_id])
-        self.__send_expect(
-            "echo %s > /sys/bus/pci/drivers/%s/new_id" % (new_id, driver), "# ")
-        self.__send_expect(
-            "echo %s > /sys/bus/pci/devices/0000\:%s\:%s/driver/unbind" %
-            (nic_pci_num, bus_id, devfun_id), "# ")
-        self.__send_expect(
-            "echo %s > /sys/bus/pci/drivers/%s/bind" %
-            (nic_pci_num, driver), "# ")
-
-    def bind_driver_linux_pci_stub(self, bus_id, devfun_id):
-        """
-        Bind NIC port to the pci-stub driver on linux.
-        """
-        new_id = self.pci_id.replace(':', ' ')
-        self.__send_expect(
-            "echo %s > /sys/bus/pci/drivers/pci-stub/new_id" % new_id, "# ")
-        self.__send_expect(
-            "echo %s > /sys/bus/pci/devices/0000\:%s\:%s/driver/unbind" %
-            (nic_pci_num, bus_id, devfun_id), "# ")
-        self.__send_expect(
-            "echo %s > /sys/bus/pci/drivers/pci-stub/bind" %
-            nic_pci_num, "# ")
-
-    @nic_has_driver
-    def unbind_driver(self, driver=''):
-        """
-        Unbind driver.
-        """
-        unbind_driver = getattr(
-            self, 'unbind_driver_%s' %
-            self.__get_os_type())
-        if not driver:
-            driver = 'generic'
-        ret = unbind_driver(self.bus_id, self.devfun_id, driver)
-        time.sleep(1)
-        return ret
-
-    def unbind_driver_linux(self, bus_id, devfun_id, driver):
-        """
-        Unbind driver on linux.
-        """
-        driver_alias = driver.replace('-', '_')
-
-        unbind_driver_linux = getattr(
-            self, 'unbind_driver_linux_%s' % driver_alias)
-        return unbind_driver_linux(bus_id, devfun_id)
-
-    def unbind_driver_linux_generic(self, bus_id, devfun_id):
-        """
-        Unbind driver by the default way on linux.
-        """
-        nic_pci_num = ':'.join(['0000', bus_id, devfun_id])
-        cmd = "echo %s > /sys/bus/pci/devices/0000\:%s\:%s/driver/unbind"
-        self.send_expect(cmd % (nic_pci_num, bus_id, devfun_id), "# ")
diff --git a/nics/net_device.py b/nics/net_device.py
new file mode 100644
index 0000000..ef39edf
--- /dev/null
+++ b/nics/net_device.py
@@ -0,0 +1,832 @@
+# BSD LICENSE
+#
+# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#   * Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#   * Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#   * Neither the name of Intel Corporation nor the names of its
+#     contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+import os
+import re
+from functools import wraps
+import time
+
+
+import settings
+from crb import Crb
+from settings import TIMEOUT
+
+NICS_LIST = []      # global list for save nic objects
+
+
+class NetDevice(object):
+
+    """
+    Abstract the device which is PF or VF.
+    """
+
+    def __init__(self, crb, bus_id, devfun_id):
+        if not isinstance(crb, Crb):
+            raise Exception("  Please input the instance of Crb!!!")
+        self.crb = crb
+        self.bus_id = bus_id
+        self.devfun_id = devfun_id
+        self.pci = bus_id + ':' + devfun_id
+        self.pci_id = get_pci_id(crb, bus_id, devfun_id)
+        self.default_driver = settings.get_nic_driver(self.pci_id)
+
+        if self.nic_is_pf():
+            self.default_vf_driver = ''
+        self.get_interface_name()
+        self.socket = self.get_nic_socket()
+
+    def close(self):
+        pass
+
+    def setup(self):
+        pass
+
+    def __send_expect(self, cmds, expected, timeout=TIMEOUT, alt_session=True):
+        """
+        Wrap the crb`s session as private session for sending expect.
+        """
+        return self.crb.send_expect(cmds, expected, timeout=timeout, alt_session=alt_session)
+
+    def __get_os_type(self):
+        """
+        Get OS type.
+        """
+        return self.crb.get_os_type()
+
+    def nic_is_pf(self):
+        """
+        It is the method that you can check if the nic is PF.
+        """
+        return True
+
+    def nic_has_driver(func):
+        """
+        Check if the NIC has a driver.
+        """
+        @wraps(func)
+        def wrapper(*args, **kwargs):
+            nic_instance = args[0]
+            nic_instance.current_driver = nic_instance.get_nic_driver()
+            if not nic_instance.current_driver:
+                return ''
+            return func(*args, **kwargs)
+        return wrapper
+
+    def get_nic_driver(self):
+        """
+        Get the NIC driver.
+        """
+        return self.crb.get_pci_dev_driver(self.bus_id, self.devfun_id)
+
+    def get_nic_socket(self):
+        """
+        Get socket id of specified pci device.
+        """
+        get_nic_socket = getattr(
+            self, 'get_nic_socket_%s' %
+            self.__get_os_type())
+        return get_nic_socket(self.bus_id, self.devfun_id)
+
+    def get_nic_socket_linux(self, bus_id, devfun_id):
+        command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/numa_node' %
+                   (bus_id, devfun_id))
+        try:
+            out = self.__send_expect(command, '# ')
+            socket = int(out)
+        except:
+            socket = -1
+        return socket
+
+    def get_nic_socket_freebsd(self, bus_id, devfun_id):
+        NotImplemented
+
+    @nic_has_driver
+    def get_interface_name(self):
+        """
+        Get interface name of specified pci device.
+        Cal this function will update intf_name everytime
+        """
+        get_interface_name = getattr(
+            self, 'get_interface_name_%s' %
+            self.__get_os_type())
+        out = get_interface_name(self.bus_id, self.devfun_id, self.current_driver)
+        if "No such file or directory" in out:
+            self.intf_name = 'N/A'
+        else:
+            self.intf_name = out
+
+        return self.intf_name
+
+    def get_interface_name_linux(self, bus_id, devfun_id, driver):
+        """
+        Get interface name of specified pci device on linux.
+        """
+        driver_alias = driver.replace('-', '_')
+        try:
+            get_interface_name_linux = getattr(
+                self,
+                'get_interface_name_linux_%s' %
+                driver_alias)
+        except Exception as e:
+            generic_driver = 'generic'
+            get_interface_name_linux = getattr(self,
+                                               'get_interface_name_linux_%s' % generic_driver)
+
+        return get_interface_name_linux(bus_id, devfun_id)
+
+    def get_interface_name_linux_virtio_pci(self, bus_id, devfun_id):
+        """
+        Get virtio device interface name by the default way on linux.
+        """
+        command = 'ls --color=never /sys/bus/pci/devices/0000\:%s\:%s/virtio*/net' % (
+            bus_id, devfun_id)
+        return self.__send_expect(command, '# ')
+
+    def get_interface_name_linux_generic(self, bus_id, devfun_id):
+        """
+        Get the interface name by the default way on linux.
+        """
+        command = 'ls --color=never /sys/bus/pci/devices/0000\:%s\:%s/net' % (
+            bus_id, devfun_id)
+        return self.__send_expect(command, '# ')
+
+    def get_interface_name_freebsd(self, bus_id, devfun_id, driver):
+        """
+        Get interface name of specified pci device on Freebsd.
+        """
+        try:
+            get_interface_name_freebsd = getattr(self,
+                                                 'get_interface_name_freebsd_%s' % driver)
+        except Exception as e:
+            generic_driver = 'generic'
+            get_interface_name_freebsd = getattr(self,
+                                                 'get_interface_name_freebsd_%s' % generic_driver)
+
+        return get_interface_name_freebsd(bus_id, devfun_id)
+
+    def get_interface_name_freebsd_generic(self, bus_id, devfun_id):
+        """
+        Get the interface name by the default way on freebsd.
+        """
+        out = self.__send_expect("pciconf -l", "# ")
+        rexp = r"(\w*)@pci0:%s" % bus_id
+        pattern = re.compile(rexp)
+        match = pattern.findall(out)
+        if len(match) == 0:
+            return "No such file"
+        return match[0]
+
+    @nic_has_driver
+    def set_vf_mac_addr(self, vf_idx=0, mac="00:00:00:00:00:01"):
+        """
+        Set mac address of specified vf device.
+        """
+        set_vf_mac_addr = getattr(self, 'set_vf_mac_addr_%s' % self.__get_os_type())
+        out = set_vf_mac_addr(self.intf_name, vf_idx, mac)
+
+    def set_vf_mac_addr_linux(self, intf, vf_idx, mac):
+        """
+        Set mac address of specified vf device on linux.
+        """
+        if self.current_driver != self.default_driver:
+            print "Only support when PF bound to default driver"
+            return
+
+        self.__send_expect("ip link set %s vf %d mac %s" % (intf, vf_idx, mac), "# ")
+
+    @nic_has_driver
+    def get_mac_addr(self):
+        """
+        Get mac address of specified pci device.
+        """
+        get_mac_addr = getattr(self, 'get_mac_addr_%s' % self.__get_os_type())
+        out = get_mac_addr(self.intf_name, self.bus_id, self.devfun_id, self.current_driver)
+        if "No such file or directory" in out:
+            return 'N/A'
+        else:
+            return out
+
+    def get_mac_addr_linux(self, intf, bus_id, devfun_id, driver):
+        """
+        Get mac address of specified pci device on linux.
+        """
+        driver_alias = driver.replace('-', '_')
+        try:
+            get_mac_addr_linux = getattr(
+                self,
+                'get_mac_addr_linux_%s' %
+                driver_alias)
+        except Exception as e:
+            generic_driver = 'generic'
+            get_mac_addr_linux = getattr(
+                self,
+                'get_mac_addr_linux_%s' %
+                generic_driver)
+
+        return get_mac_addr_linux(intf, bus_id, devfun_id, driver)
+
+    def get_mac_addr_linux_generic(self, intf, bus_id, devfun_id, driver):
+        """
+        Get MAC by the default way on linux.
+        """
+        command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/net/%s/address' %
+                   (bus_id, devfun_id, intf))
+        return self.__send_expect(command, '# ')
+
+    def get_mac_addr_linux_virtio_pci(self, intf, bus_id, devfun_id, driver):
+        """
+        Get MAC by the default way on linux.
+        """
+        virtio_cmd = ('ls /sys/bus/pci/devices/0000\:%s\:%s/ | grep --color=never virtio' %
+                      (bus_id, devfun_id))
+        virtio = self.__send_expect(virtio_cmd, '# ')
+
+        command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/%s/net/%s/address' %
+                   (bus_id, devfun_id, virtio, intf))
+        return self.__send_expect(command, '# ')
+
+    def get_mac_addr_freebsd(self, intf, bus_id, devfun_id, driver):
+        """
+        Get mac address of specified pci device on Freebsd.
+        """
+        try:
+            get_mac_addr_freebsd = getattr(
+                self,
+                'get_mac_addr_freebsd_%s' %
+                driver)
+        except Exception as e:
+            generic_driver = 'generic'
+            get_mac_addr_freebsd = getattr(
+                self,
+                'get_mac_addr_freebsd_%s' %
+                generic_driver)
+
+        return get_mac_addr_freebsd(intf, bus_id, devfun_id)
+
+    def get_mac_addr_freebsd_generic(self, intf, bus_id, devfun_id):
+        """
+        Get the MAC by the default way on Freebsd.
+        """
+        out = self.__send_expect('ifconfig %s' % intf, '# ')
+        rexp = r"ether ([\da-f:]*)"
+        pattern = re.compile(rexp)
+        match = pattern.findall(out)
+        return match[0]
+
+    @nic_has_driver
+    def get_ipv4_addr(self):
+        """
+        Get ipv4 address of specified pci device.
+        """
+        get_ipv4_addr = getattr(
+            self, 'get_ipv4_addr_%s' % self.__get_os_type())
+        return get_ipv4_addr(self.intf_name, self.currenct_driver)
+
+    def get_ipv4_addr_linux(self, intf, driver):
+        """
+        Get ipv4 address of specified pci device on linux.
+        """
+        try:
+            get_ipv4_addr_linux = getattr(self, 'get_ipv4_linux_%s' % driver)
+        except Exception as e:
+            generic_driver = 'generic'
+            get_ipv4_addr_linux = getattr(
+                self, 'get_ipv4_linux_%s' %
+                generic_driver)
+
+        return get_ipv4_addr_linux(intf, bus_id, devfun_id, driver)
+
+    def get_ipv4_addr_linux_generic(self, intf):
+        """
+        Get IPv4 address by the default way on linux.
+        """
+        out = self.__send_expect("ip -family inet address show dev %s | awk '/inet/ { print $2 }'"
+                                 % intf, "# ")
+        return out.split('/')[0]
+
+    def get_ipv4_addr_freebsd(self, intf, driver):
+        """
+        Get ipv4 address of specified pci device on Freebsd.
+        """
+        try:
+            get_ipv4_addr_freebsd = getattr(
+                self,
+                'get_ipv4_addr_freebsd_%s' %
+                driver)
+        except Exception as e:
+            generic_driver = 'generic'
+            get_ipv4_addr_freebsd = getattr(
+                self,
+                'get_ipv4_addr_freebsd_%s' %
+                generic_driver)
+
+        return get_ipv4_addr_freebsd(intf, bus_id, devfun_id)
+
+    def get_ipv4_addr_freebsd_generic(self, intf):
+        """
+        Get the IPv4 address by the default way on Freebsd.
+        """
+        out = self.__send_expect('ifconfig %s' % intf, '# ')
+        rexp = r"inet ([\d:]*)%"
+        pattern = re.compile(rexp)
+        match = pattern.findall(out)
+        if len(match) == 0:
+            return None
+
+        return match[0]
+
+    @nic_has_driver
+    def enable_ipv6(self):
+        """
+        Enable ipv6 address of specified pci device.
+        """
+        if self.current_driver != self.default_driver:
+            return
+
+        enable_ipv6 = getattr(
+            self, 'enable_ipv6_%s' % self.__get_os_type())
+        return enable_ipv6(self.intf_name)
+
+    def enable_ipv6_linux(self, intf):
+        """
+        Enable ipv6 address of specified pci device on linux.
+        """
+        self.__send_expect("sysctl net.ipv6.conf.%s.disable_ipv6=0" %
+                           intf, "# ")
+        # FVL interface need down and up for re-enable ipv6
+        if self.default_driver == 'i40e':
+            self.__send_expect("ifconfig %s down" % intf, "# ")
+            self.__send_expect("ifconfig %s up" % intf, "# ")
+
+    def enable_ipv6_freebsd(self, intf):
+        pass
+
+    @nic_has_driver
+    def disable_ipv6(self):
+        """
+        Disable ipv6 address of specified pci device.
+        """
+        if self.current_driver != self.default_driver:
+            return
+        disable_ipv6 = getattr(
+            self, 'disable_ipv6_%s' % self.__get_os_type())
+        return disable_ipv6(self.intf_name)
+
+    def disable_ipv6_linux(self, intf):
+        """
+        Disable ipv6 address of specified pci device on linux.
+        """
+        self.__send_expect("sysctl net.ipv6.conf.%s.disable_ipv6=1" %
+                           intf, "# ")
+
+    def disable_ipv6_freebsd(self, intf):
+        pass
+
+    @nic_has_driver
+    def get_ipv6_addr(self):
+        """
+        Get ipv6 address of specified pci device.
+        """
+        get_ipv6_addr = getattr(
+            self, 'get_ipv6_addr_%s' % self.__get_os_type())
+        return get_ipv6_addr(self.intf_name, self.current_driver)
+
+    @nic_has_driver
+    def get_ipv6_addr(self):
+        """
+        Get ipv6 address of specified pci device.
+        """
+        get_ipv6_addr = getattr(
+            self, 'get_ipv6_addr_%s' % self.__get_os_type())
+        return get_ipv6_addr(self.intf_name, self.current_driver)
+
+    def get_ipv6_addr_linux(self, intf, driver):
+        """
+        Get ipv6 address of specified pci device on linux.
+        """
+        try:
+            get_ipv6_addr_linux = getattr(
+                self,
+                'get_ipv6_addr_linux_%s' %
+                driver)
+        except Exception as e:
+            generic_driver = 'generic'
+            get_ipv6_addr_linux = getattr(
+                self,
+                'get_ipv6_addr_linux_%s' %
+                generic_driver)
+
+        return get_ipv6_addr_linux(intf)
+
+    def get_ipv6_addr_linux_generic(self, intf):
+        """
+        Get the IPv6 address by the default way on linux.
+        """
+        out = self.__send_expect("ip -family inet6 address show dev %s | awk '/inet6/ { print $2 }'"
+                                 % intf, "# ")
+        return out.split('/')[0]
+
+    def get_ipv6_addr_freebsd(self, intf, driver):
+        """
+        Get ipv6 address of specified pci device on Freebsd.
+        """
+        try:
+            get_ipv6_addr_freebsd = getattr(
+                self,
+                'get_ipv6_addr_freebsd_%s' %
+                driver)
+        except Exception as e:
+            generic_driver = 'generic'
+            get_ipv6_addr_freebsd = getattr(
+                self,
+                'get_ipv6_addr_freebsd_%s' %
+                generic_driver)
+
+        return get_ipv6_addr_freebsd(intf)
+
+    def get_ipv6_addr_freebsd_generic(self, intf):
+        """
+        Get the IPv6 address by the default way on Freebsd.
+        """
+        out = self.__send_expect('ifconfig %s' % intf, '# ')
+        rexp = r"inet6 ([\da-f:]*)%"
+        pattern = re.compile(rexp)
+        match = pattern.findall(out)
+        if len(match) == 0:
+            return None
+
+        return match[0]
+
+    def get_nic_numa(self):
+        """
+        Get numa number of specified pci device.
+        """
+        self.crb.get_nic_numa(self.bus_id, self.devfun_id)
+
+    def get_card_type(self):
+        """
+        Get card type of specified pci device.
+        """
+        return self.crb.get_pci_dev_id(self.bus_id, self.devfun_id)
+
+    @nic_has_driver
+    def get_sriov_vfs_pci(self):
+        """
+        Get all SRIOV VF pci bus of specified pci device.
+        """
+        get_sriov_vfs_pci = getattr(
+            self, 'get_sriov_vfs_pci_%s' % self.__get_os_type())
+        return get_sriov_vfs_pci(self.bus_id, self.devfun_id, self.current_driver)
+
+    def get_sriov_vfs_pci_linux(self, bus_id, devfun_id, driver):
+        """
+        Get all SRIOV VF pci bus of specified pci device on linux.
+        """
+        try:
+            get_sriov_vfs_pci_linux = getattr(
+                self,
+                'get_sriov_vfs_pci_linux_%s' %
+                driver)
+        except Exception as e:
+            generic_driver = 'generic'
+            get_sriov_vfs_pci_linux = getattr(
+                self,
+                'get_sriov_vfs_pci_linux_%s' %
+                generic_driver)
+
+        return get_sriov_vfs_pci_linux(bus_id, devfun_id)
+
+    def get_sriov_vfs_pci_linux_generic(self, bus_id, devfun_id):
+        """
+        Get all the VF PCIs of specified PF by the default way on linux.
+        """
+        sriov_numvfs = self.__send_expect(
+            "cat /sys/bus/pci/devices/0000\:%s\:%s/sriov_numvfs" %
+            (bus_id, devfun_id), "# ")
+        sriov_vfs_pci = []
+
+        if "No such file" in sriov_numvfs:
+            return sriov_vfs_pci
+
+        if int(sriov_numvfs) == 0:
+            pass
+        else:
+            try:
+                virtfns = self.__send_expect(
+                    "ls -d /sys/bus/pci/devices/0000\:%s\:%s/virtfn*" %
+                    (bus_id, devfun_id), "# ")
+                for virtfn in virtfns.split():
+                    vf_uevent = self.__send_expect(
+                        "cat %s" %
+                        os.path.join(virtfn, "uevent"), "# ")
+                    vf_pci = re.search(
+                        r"PCI_SLOT_NAME=0000:([0-9a-f]+:[0-9a-f]+\.[0-9a-f]+)",
+                        vf_uevent).group(1)
+                    sriov_vfs_pci.append(vf_pci)
+            except Exception as e:
+                print "Scan linux port [0000:%s.%s] sriov vf failed: %s" % (bus_id, devfun_id, e)
+
+        return sriov_vfs_pci
+
+    @nic_has_driver
+    def generate_sriov_vfs(self, vf_num):
+        """
+        Generate some numbers of SRIOV VF.
+        """
+        if vf_num == 0:
+            self.bind_vf_driver()
+        generate_sriov_vfs = getattr(
+            self, 'generate_sriov_vfs_%s' %
+            self.__get_os_type())
+        generate_sriov_vfs(
+            self.bus_id,
+            self.devfun_id,
+            vf_num,
+            self.current_driver)
+        if vf_num != 0:
+            self.sriov_vfs_pci = self.get_sriov_vfs_pci()
+
+            vf_pci = self.sriov_vfs_pci[0]
+            addr_array = vf_pci.split(':')
+            bus_id = addr_array[0]
+            devfun_id = addr_array[1]
+
+            self.default_vf_driver = self.crb.get_pci_dev_driver(
+                bus_id, devfun_id)
+        else:
+            self.sriov_vfs_pci = []
+        time.sleep(1)
+
+    def generate_sriov_vfs_linux(self, bus_id, devfun_id, vf_num, driver):
+        """
+        Generate some numbers of SRIOV VF.
+        """
+        try:
+            generate_sriov_vfs_linux = getattr(
+                self,
+                'generate_sriov_vfs_linux_%s' %
+                driver)
+        except Exception as e:
+            generic_driver = 'generic'
+            generate_sriov_vfs_linux = getattr(
+                self,
+                'generate_sriov_vfs_linux_%s' %
+                generic_driver)
+
+        return generate_sriov_vfs_linux(bus_id, devfun_id, vf_num)
+
+    def generate_sriov_vfs_linux_generic(self, bus_id, devfun_id, vf_num):
+        """
+        Generate SRIOV VFs by the default way on linux.
+        """
+        nic_driver = self.get_nic_driver()
+
+        if not nic_driver:
+            return None
+
+        vf_reg_file = "sriov_numvfs"
+        vf_reg_path = os.path.join("/sys/bus/pci/devices/0000:%s:%s" %
+                                   (bus_id, devfun_id), vf_reg_file)
+        self.__send_expect("echo %d > %s" %
+                           (int(vf_num), vf_reg_path), "# ")
+
+    def generate_sriov_vfs_linux_igb_uio(self, bus_id, devfun_id, vf_num):
+        """
+        Generate SRIOV VFs by the special way of igb_uio driver on linux.
+        """
+        nic_driver = self.get_nic_driver()
+
+        if not nic_driver:
+            return None
+
+        vf_reg_file = "max_vfs"
+        if self.default_driver == 'i40e':
+            regx_reg_path = "find /sys -name %s | grep %s:%s" % (vf_reg_file, bus_id, devfun_id)
+            vf_reg_path = self.__send_expect(regx_reg_path, "# ")
+        else:
+            vf_reg_path = os.path.join("/sys/bus/pci/devices/0000:%s:%s" %
+                                       (bus_id, devfun_id), vf_reg_file)
+        self.__send_expect("echo %d > %s" %
+                           (int(vf_num), vf_reg_path), "# ")
+
+    def destroy_sriov_vfs(self):
+        """
+        Destroy the SRIOV VFs.
+        """
+        self.generate_sriov_vfs(0)
+
+    def bind_vf_driver(self, pci='', driver=''):
+        """
+        Bind the specified driver to VF.
+        """
+        bind_vf_driver = getattr(self, 'bind_driver_%s' % self.__get_os_type())
+        if not driver:
+            if not self.default_vf_driver:
+                print "Must specify a driver because default VF driver is NULL!"
+                return
+            driver = self.default_vf_driver
+
+        if not pci:
+            if not self.sriov_vfs_pci:
+                print "No VFs on the nic [%s]!" % self.pci
+                return
+            for vf_pci in self.sriov_vfs_pci:
+                addr_array = vf_pci.split(':')
+                bus_id = addr_array[0]
+                devfun_id = addr_array[1]
+
+                bind_vf_driver(bus_id, devfun_id, driver)
+        else:
+            addr_array = pci.split(':')
+            bus_id = addr_array[0]
+            devfun_id = addr_array[1]
+
+            bind_vf_driver(bus_id, devfun_id, driver)
+
+    def bind_driver(self, driver=''):
+        """
+        Bind specified driver to PF.
+        """
+        bind_driver = getattr(self, 'bind_driver_%s' % self.__get_os_type())
+        if not driver:
+            if not self.default_driver:
+                print "Must specify a driver because default driver is NULL!"
+                return
+            driver = self.default_driver
+        ret = bind_driver(self.bus_id, self.devfun_id, driver)
+        time.sleep(1)
+        return ret
+
+    def bind_driver_linux(self, bus_id, devfun_id, driver):
+        """
+        Bind NIC port to specified driver on linux.
+        """
+        driver_alias = driver.replace('-', '_')
+        try:
+            bind_driver_linux = getattr(
+                self,
+                'bind_driver_linux_%s' %
+                driver_alias)
+            return bind_driver_linux(bus_id, devfun_id)
+        except Exception as e:
+            driver_alias = 'generic'
+            bind_driver_linux = getattr(
+                self,
+                'bind_driver_linux_%s' %
+                driver_alias)
+            return bind_driver_linux(bus_id, devfun_id, driver)
+
+    def bind_driver_linux_generic(self, bus_id, devfun_id, driver):
+        """
+        Bind NIC port to specified driver by the default way on linux.
+        """
+        new_id = self.pci_id.replace(':', ' ')
+        nic_pci_num = ':'.join(['0000', bus_id, devfun_id])
+        self.__send_expect(
+            "echo %s > /sys/bus/pci/drivers/%s/new_id" % (new_id, driver), "# ")
+        self.__send_expect(
+            "echo %s > /sys/bus/pci/devices/0000\:%s\:%s/driver/unbind" %
+            (nic_pci_num, bus_id, devfun_id), "# ")
+        self.__send_expect(
+            "echo %s > /sys/bus/pci/drivers/%s/bind" %
+            (nic_pci_num, driver), "# ")
+
+    def bind_driver_linux_pci_stub(self, bus_id, devfun_id):
+        """
+        Bind NIC port to the pci-stub driver on linux.
+        """
+        new_id = self.pci_id.replace(':', ' ')
+        self.__send_expect(
+            "echo %s > /sys/bus/pci/drivers/pci-stub/new_id" % new_id, "# ")
+        self.__send_expect(
+            "echo %s > /sys/bus/pci/devices/0000\:%s\:%s/driver/unbind" %
+            (nic_pci_num, bus_id, devfun_id), "# ")
+        self.__send_expect(
+            "echo %s > /sys/bus/pci/drivers/pci-stub/bind" %
+            nic_pci_num, "# ")
+
+    @nic_has_driver
+    def unbind_driver(self, driver=''):
+        """
+        Unbind driver.
+        """
+        unbind_driver = getattr(
+            self, 'unbind_driver_%s' %
+            self.__get_os_type())
+        if not driver:
+            driver = 'generic'
+        ret = unbind_driver(self.bus_id, self.devfun_id, driver)
+        time.sleep(1)
+        return ret
+
+    def unbind_driver_linux(self, bus_id, devfun_id, driver):
+        """
+        Unbind driver on linux.
+        """
+        driver_alias = driver.replace('-', '_')
+
+        unbind_driver_linux = getattr(
+            self, 'unbind_driver_linux_%s' % driver_alias)
+        return unbind_driver_linux(bus_id, devfun_id)
+
+    def unbind_driver_linux_generic(self, bus_id, devfun_id):
+        """
+        Unbind driver by the default way on linux.
+        """
+        nic_pci_num = ':'.join(['0000', bus_id, devfun_id])
+        cmd = "echo %s > /sys/bus/pci/devices/0000\:%s\:%s/driver/unbind"
+        self.send_expect(cmd % (nic_pci_num, bus_id, devfun_id), "# ")
+
+
+def get_pci_id(crb, bus_id, devfun_id):
+    """
+    Return pci device type
+    """
+    command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/vendor' %
+               (bus_id, devfun_id))
+    out = crb.send_expect(command, "# ")
+    vender = out[2:]
+    command = ('cat /sys/bus/pci/devices/0000\:%s\:%s/device' %
+               (bus_id, devfun_id))
+    out = crb.send_expect(command, '# ')
+    device = out[2:]
+    return "%s:%s" % (vender, device)
+
+
+def add_to_list(host, obj):
+    """
+    Add network device object to global structure
+    Parameter 'host' is ip address, 'obj' is netdevice object
+    """
+    nic = {}
+    nic['host'] = host
+    nic['pci'] = obj.pci
+    nic['port'] = obj
+    NICS_LIST.append(nic)
+
+
+def get_from_list(host, bus_id, devfun_id):
+    """
+    Get network device object from global structure
+    Parameter will by host ip, pci bus id, pci function id
+    """
+    for nic in NICS_LIST:
+        if host == nic['host']:
+            pci = ':'.join((bus_id, devfun_id))
+            if pci == nic['pci']:
+                return nic['port']
+    return None
+
+
+def GetNicObj(crb, bus_id, devfun_id):
+    """
+    Get network device object. If network device has been initialized, just
+    return object. Based on nic type, some special nics like RRC will return
+    object different from default.
+    """
+    # find existed NetDevice object
+    obj = get_from_list(crb.crb['IP'], bus_id, devfun_id)
+    if obj:
+        return obj
+
+    pci_id = get_pci_id(crb, bus_id, devfun_id)
+    nic = settings.get_nic_name(pci_id)
+
+    if nic == 'redrockcanyou':
+        # redrockcanyou nic need special initialization
+        from fm10k import RedRockCanyou
+        obj = RedRockCanyou(crb, bus_id, devfun_id)
+    else:
+        obj = NetDevice(crb, bus_id, devfun_id)
+
+    add_to_list(crb.crb['IP'], obj)
+    return obj
-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dts] [PATCH 4/8] nics: add fm10k module for RedRockCanYou family nic
  2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
                   ` (2 preceding siblings ...)
  2015-12-13  4:57 ` [dts] [PATCH 3/8] framework: create independent foler for nic modules Yong Liu
@ 2015-12-13  4:57 ` Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 5/8] framework: net device object get from net_device module Yong Liu
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yong Liu @ 2015-12-13  4:57 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

This module will support fm10k family nics. These nics required special
testpoint for internal switch initialization. Some nics like BulderRapid
must start up testpoint after bound to igb_uio.

Most features like vlan need special configured in testpoint. Those
functions will be realized in fm10k module.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/nics/fm10k.py b/nics/fm10k.py
new file mode 100644
index 0000000..ab35981
--- /dev/null
+++ b/nics/fm10k.py
@@ -0,0 +1,164 @@
+# BSD LICENSE
+#
+# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#   * Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#   * Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#   * Neither the name of Intel Corporation nor the names of its
+#     contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from crb import Crb
+from config import PortConf, PORTCONF
+from exception import PortConfigParseException
+from utils import GREEN
+from net_device import NetDevice
+
+DEF_PASSWD = 's'
+TP_BINARY = 'TestPoint'
+
+
+class CtrlCrb(Crb):
+    """
+    Simplified Crb class for  RedRockCanyou control session
+    """
+
+    def __init__(self, crb):
+        self.crb = crb
+        self.NAME = 'dut_RRC_CONTROL'
+        super(CtrlCrb, self).__init__(crb, None, self.NAME)
+
+    def get_ip_address(self):
+        return self.crb['IP']
+
+    def get_password(self):
+        return self.crb['pass']
+
+
+class RedRockCanyou(NetDevice):
+    """
+    Class for RedRockCanyou, inherit from NetDevice class
+    """
+
+    def __init__(self, host, bus_id, devfun_id):
+        super(RedRockCanyou, self).__init__(host, bus_id, devfun_id)
+        self.tp_path = "~"
+        self.sec_port = False
+        self.host = host
+
+        # load port config
+        portconf = PortConf(PORTCONF)
+        portconf.load_ports_config(host.crb['IP'])
+        pci_addr = ':'.join((bus_id, devfun_id))
+        if not portconf.check_port_available(pci_addr):
+            raise PortConfigParseException("RRC must configured")
+
+        port_cfg = portconf.get_ports_config()[pci_addr]
+
+        # secondary port do not need reinitialize
+        if 'sec_port' in port_cfg.keys():
+            print GREEN("Skip init second port test point session")
+            if 'first_port' not in port_cfg.keys():
+                raise PortConfigParseException("RRC second port must configure first port")
+            # find net_device by pci_addr
+            first_addr = port_cfg['first_port']
+            port_info = self.host.get_port_info(first_addr)
+            if port_info is None:
+                raise PortConfigParseException("RRC first port not found")
+            # get addtional session
+            netdev = port_info['port']
+            self.ctrl_crb = netdev.get_control()
+            self.sec_port = True
+            return
+
+        if 'tp_ip' not in port_cfg.keys():
+            raise PortConfigParseException("RRC must configure test point ip")
+
+        crb = {}
+        crb['IP'] = port_cfg['tp_ip']
+        if 'passwd' not in port_cfg.keys():
+            crb['pass'] = DEF_PASSWD
+        else:
+            crb['pass'] = port_cfg['passwd']
+
+        if 'tp_path' in port_cfg.keys():
+            self.tp_path = port_cfg['tp_path']
+
+        # create addtional session
+        self.ctrl_crb = CtrlCrb(crb)
+
+    def setup(self):
+        # setup function should be called after bind to igb_uio
+        self.start_testpoint()
+
+    def close(self):
+        # second port do not need any operation
+        if self.sec_port:
+            return
+
+        # stop testpoint
+        self.stop_testpoint()
+        # close session
+        if self.ctrl_crb.session:
+            self.ctrl_crb.session.close()
+            self.ctrl_crb.session = None
+        if self.ctrl_crb.alt_session:
+            self.ctrl_crb.alt_session.close()
+            self.ctrl_crb.alt_session = None
+
+    def start_testpoint(self):
+        """
+        Before any execution, must enable test point first
+        """
+        if self.sec_port:
+            print GREEN("Skip start second port testpoint")
+            return
+        self.ctrl_crb.send_expect("cd %s" % self.tp_path, "# ")
+        if self.tp_path != "~":
+            command = './' + TP_BINARY
+        else:
+            command = TP_BINARY
+
+        self.ctrl_crb.send_expect("%s" % command, "<0>%", 120)
+
+    def stop_testpoint(self):
+        """
+        Exit test point
+        """
+        self.ctrl_crb.send_expect("quit", "# ")
+
+    def get_control(self):
+        return self.ctrl_crb
+
+    def enable_vlan(self, vlan_id=0):
+        self.ctrl_crb.send_expect("create vlan %d" % vlan_id, "<0>%")
+        self.ctrl_crb.send_expect("add vlan port %d 1,5,20,22" % vlan_id, "<0>%")
+    
+    def disable_vlan(self, vlan_id=0):
+        self.ctrl_crb.send_expect("del vlan port %d 1,5,20,22" % vlan_id, "<0>%")
+        self.ctrl_crb.send_expect("del vlan %d" % vlan_id, "<0>%")
+
+    def enable_jumbo(self):
+        NotImplemented
-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dts] [PATCH 5/8] framework: net device object get from net_device module
  2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
                   ` (3 preceding siblings ...)
  2015-12-13  4:57 ` [dts] [PATCH 4/8] nics: add fm10k module for RedRockCanYou family nic Yong Liu
@ 2015-12-13  4:57 ` Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 6/8] framework dts: close netdevice related session after exit Yong Liu
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yong Liu @ 2015-12-13  4:57 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

All net device object will be retrieved from net_device module. If
there has been the object for required nic, net_device module will just
return it without re-initialized it.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/dut.py b/framework/dut.py
index 2101fc8..fde5071 100644
--- a/framework/dut.py
+++ b/framework/dut.py
@@ -38,7 +38,7 @@ from config import PortConf
 from settings import NICS, LOG_NAME_SEP
 from ssh_connection import SSHConnection
 from crb import Crb
-from net_device import NetDevice
+from net_device import GetNicObj
 from virt_resource import VirtResource
 from utils import RED
 from uuid import uuid4
@@ -240,7 +240,7 @@ class Dut(Crb):
                 bus_id = addr_array[0]
                 devfun_id = addr_array[1]
 
-                port = NetDevice(self, bus_id, devfun_id)
+                port = GetNicObj(self, bus_id, devfun_id)
 
                 self.send_expect('echo 0000:%s > /sys/bus/pci/devices/0000\:%s\:%s/driver/unbind'
                                  % (pci_bus, bus_id, devfun_id), '# ')
@@ -476,14 +476,6 @@ class Dut(Crb):
 
         return self.ports_info[port_num]['numa']
 
-    def get_port_info(self, pci):
-        """
-        return port info by pci id
-        """
-        for port_info in self.ports_info:
-            if port_info['pci'] == pci:
-                return port_info
-
     def lcore_table_print(self, horizontal=False):
         if not horizontal:
             dts.results_table_add_header(['Socket', 'Core', 'Thread'])
@@ -631,7 +623,7 @@ class Dut(Crb):
             return
 
         for port_info in self.ports_info:
-            port = NetDevice(self, port_info['pci'], port_info['type'])
+            port = GetNicObj(self, port_info['pci'], port_info['type'])
             intf = port.get_interface_name()
 
             self.logger.info("DUT cached: [000:%s %s] %s" % (port_info['pci'],
@@ -665,7 +657,7 @@ class Dut(Crb):
             bus_id = addr_array[0]
             devfun_id = addr_array[1]
 
-            port = NetDevice(self, bus_id, devfun_id)
+            port = GetNicObj(self, bus_id, devfun_id)
             numa = port.socket
             # store the port info to port mapping
             self.ports_info.append(
@@ -686,7 +678,7 @@ class Dut(Crb):
                                                       skipped))
                 continue
 
-            port = NetDevice(self, pci_bus, '')
+            port = GetNicObj(self, pci_bus, '')
             intf = port.get_interface_name()
 
             macaddr = port.get_mac_addr()
@@ -734,13 +726,13 @@ class Dut(Crb):
         sriov_vfs_pci = port.get_sriov_vfs_pci()
         self.ports_info[port_id]['sriov_vfs_pci'] = sriov_vfs_pci
 
-        # instantiate the VF with NetDevice
+        # instantiate the VF
         vfs_port = []
         for vf_pci in sriov_vfs_pci:
             addr_array = vf_pci.split(':')
             bus_id = addr_array[0]
             devfun_id = addr_array[1]
-            vf_port = NetDevice(self, bus_id, devfun_id)
+            vf_port = GetNicObj(self, bus_id, devfun_id)
             vfs_port.append(vf_port)
         self.ports_info[port_id]['vfs_port'] = vfs_port
 
diff --git a/framework/virt_dut.py b/framework/virt_dut.py
index 8d0c5d9..1292d08 100644
--- a/framework/virt_dut.py
+++ b/framework/virt_dut.py
@@ -38,7 +38,7 @@ from config import PortConf
 from settings import NICS, LOG_NAME_SEP, get_netdev
 from project_dpdk import DPDKdut
 from dut import Dut
-from net_device import NetDevice
+from net_device import GetNicObj
 
 
 class VirtDut(DPDKdut):
@@ -252,7 +252,7 @@ class VirtDut(DPDKdut):
                 addr_array = pci_bus.split(':')
                 bus_id = addr_array[0]
                 devfun_id = addr_array[1]
-                port = NetDevice(self, bus_id, devfun_id)
+                port = GetNicObj(self, bus_id, devfun_id)
                 itf = port.get_interface_name()
                 self.send_expect("ifconfig %s up" % itf, "# ")
                 time.sleep(30)
-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dts] [PATCH 6/8] framework dts: close netdevice related session after exit
  2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
                   ` (4 preceding siblings ...)
  2015-12-13  4:57 ` [dts] [PATCH 5/8] framework: net device object get from net_device module Yong Liu
@ 2015-12-13  4:57 ` Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 7/8] conf: add sample for RedRockCanYou family nic Yong Liu
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yong Liu @ 2015-12-13  4:57 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Net device will also created sessions. dts module should also close
those sessions.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/dts.py b/framework/dts.py
index 30c39ab..8e0be62 100644
--- a/framework/dts.py
+++ b/framework/dts.py
@@ -41,9 +41,10 @@ import signal       # signal module for debug mode
 import time         # time module for unique output folder
 
 import rst          # rst file support
+import sys          # system module
+from settings import FOLDERS, NICS
 from tester import Tester
 from dut import Dut
-from settings import FOLDERS, NICS, DRIVERS
 from serializer import Serializer
 from exception import VerifyFailure
 from test_case import TestCase
@@ -99,10 +100,15 @@ def report(text, frame=False, annex=False):
         rst.write_text(text, annex)
 
 
-def close_crb_sessions():
+def close_all_sessions():
     """
     Close session to DUT and tester.
     """
+    # close all nics
+    for port_info in dut.ports_info:
+        netdev = port_info['port']
+        netdev.close()
+    # close all session
     if dut is not None:
         dut.close()
     if tester is not None:
@@ -418,8 +424,6 @@ def run_all(config_file, pkgName, git, patch, skip_setup,
         os.mkdir(output_dir)
 
     # add python module search path
-    for folder in FOLDERS.values():
-        sys.path.append(folder)
     sys.path.append(suite_dir)
 
     # enable debug mode
@@ -446,7 +450,7 @@ def run_all(config_file, pkgName, git, patch, skip_setup,
         raise ConfigParseException(config_file)
 
     # register exit action
-    atexit.register(close_crb_sessions)
+    atexit.register(close_all_sessions)
 
     os.environ["TERM"] = "dumb"
 
-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dts] [PATCH 7/8] conf: add sample for RedRockCanYou family nic
  2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
                   ` (5 preceding siblings ...)
  2015-12-13  4:57 ` [dts] [PATCH 6/8] framework dts: close netdevice related session after exit Yong Liu
@ 2015-12-13  4:57 ` Yong Liu
  2015-12-13  4:57 ` [dts] [PATCH 8/8] framework project_dpdk: add extra setup after bind driver Yong Liu
  2015-12-14  1:34 ` [dts] [RFC PATCH 0/8] support fm10k family nics Liu, Yong
  8 siblings, 0 replies; 10+ messages in thread
From: Yong Liu @ 2015-12-13  4:57 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/conf/ports.cfg b/conf/ports.cfg
index 27ebfe0..2c9a60a 100644
--- a/conf/ports.cfg
+++ b/conf/ports.cfg
@@ -4,6 +4,8 @@
 #     pci=Pci BDF,intf=Kernel interface;
 #     pci=Pci BDF,mac=Mac address,peer=Tester Pci BDF,numa=Port Numa 
 #     pci=Pci BDF,peer=IXIA:card.port
+#     pci=Pci BDF,peer=Tester Pci BDF,tp_ip=$(IP),tp_path=$({PERL_PATH);
+#     pci=Pci BDF,peer=Tester Pci BDF,sec_port=yes,first_port=Pci BDF;
 # [VM NAME] virtual machine name; This section is for virutal scenario
 # ports =
 #     dev_idx=device index of ports info, peer=Tester Pci BDF
@@ -11,7 +13,9 @@
 ports =
     pci=XX:XX.X,intf=eth0;
     pci=YY:YY.Y,mac=XX:XX:XX:XX:XX:XX,peer=ZZ:ZZ.Z,numa=0;
-    pci=ZZ:ZZ.Y,peer=IXIA:X.Y
+    pci=ZZ:ZZ.Y,peer=IXIA:X.Y;
+    pci=XX:XX.X,peer=ZZ:ZZ.Z,tp_ip=127.0.0.1,tp_path=/home/libertyTrailTP_322291/perl;
+    pci=YY:YY.Y,peer=ZZ:ZZ.Z,sec_port=yes,first_port=XX:XX.X;
 [VM NAME]
 ports =
     dev_idx=0,peer=XX:XX.X;
-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dts] [PATCH 8/8] framework project_dpdk: add extra setup after bind driver
  2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
                   ` (6 preceding siblings ...)
  2015-12-13  4:57 ` [dts] [PATCH 7/8] conf: add sample for RedRockCanYou family nic Yong Liu
@ 2015-12-13  4:57 ` Yong Liu
  2015-12-14  1:34 ` [dts] [RFC PATCH 0/8] support fm10k family nics Liu, Yong
  8 siblings, 0 replies; 10+ messages in thread
From: Yong Liu @ 2015-12-13  4:57 UTC (permalink / raw)
  To: dts

From: Marvin Liu <yong.liu@intel.com>

Some nics like RRC required extra setup after bind to igb_uio.
Those setup functions will be realized in nic modules.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/project_dpdk.py b/framework/project_dpdk.py
index 1c2f095..538a3b7 100644
--- a/framework/project_dpdk.py
+++ b/framework/project_dpdk.py
@@ -78,6 +78,7 @@ class DPDKdut(Dut):
 
         if bind_dev and self.get_os_type() == 'linux':
             self.bind_interfaces_linux(dts.drivername)
+        self.extra_nic_setup()
 
     def setup_modules(self, target):
         """
@@ -255,6 +256,14 @@ class DPDKdut(Dut):
         self.prepare_package(pkgName, patch)
         self.dut_prerequisites()
 
+    def extra_nic_setup(self):
+        """
+        Some nic like RRC required additional setup after module installed
+        """
+        for port_info in self.ports_info:
+            netdev = port_info['port']
+            netdev.setup()
+
     def bind_interfaces_linux(self, driver='igb_uio', nics_to_bind=None):
         """
         Bind the interfaces to the selected driver. nics_to_bind can be None
-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dts] [RFC PATCH 0/8] support fm10k family nics
  2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
                   ` (7 preceding siblings ...)
  2015-12-13  4:57 ` [dts] [PATCH 8/8] framework project_dpdk: add extra setup after bind driver Yong Liu
@ 2015-12-14  1:34 ` Liu, Yong
  8 siblings, 0 replies; 10+ messages in thread
From: Liu, Yong @ 2015-12-14  1:34 UTC (permalink / raw)
  To: dts

Merged into next branch. Will merge to master branch after fully validation.

On 12/13/2015 12:57 PM, Yong Liu wrote:
> fm10k family nics required addtional setup functions for testpoint. All
> functions will be enabled after startup and configure testpoint. For some nics
> like RubyRapid and BulderRapid, two ports will share one testpoint.
>
> For clearify nic functions, created another folder named "nics" which will
> contained all nic modules.
>
> Marvin Liu (8):
>    framework settings: rename nic_name_from_type to get_nic_name
>    framework crb: add function to retrieve port information
>    framework: create independent foler for nic modules
>    nics: add fm10k module for RedRockCanYou family nic
>    framework: net device object get from net_device module
>    framework dts: close netdevice related session after exit
>    conf: add sample for RedRockCanYou family nic
>    framework project_dpdk: add extra setup after bind driver
>
>   conf/ports.cfg            |   6 +-
>   framework/checkCase.py    |   4 +-
>   framework/crb.py          |   8 +
>   framework/dts.py          |  14 +-
>   framework/dut.py          |  22 +-
>   framework/main.py         |   6 +-
>   framework/net_device.py   | 770 ------------------------------------------
>   framework/project_dpdk.py |   9 +
>   framework/settings.py     |   3 +-
>   framework/test_case.py    |   4 +-
>   framework/virt_dut.py     |   4 +-
>   nics/fm10k.py             | 164 +++++++++
>   nics/net_device.py        | 832 ++++++++++++++++++++++++++++++++++++++++++++++
>   13 files changed, 1047 insertions(+), 799 deletions(-)
>   delete mode 100644 framework/net_device.py
>   create mode 100644 nics/fm10k.py
>   create mode 100644 nics/net_device.py
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-12-14  1:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-13  4:57 [dts] [RFC PATCH 0/8] support fm10k family nics Yong Liu
2015-12-13  4:57 ` [dts] [PATCH 1/8] framework settings: rename nic_name_from_type to get_nic_name Yong Liu
2015-12-13  4:57 ` [dts] [PATCH 2/8] framework crb: add function to retrieve port information Yong Liu
2015-12-13  4:57 ` [dts] [PATCH 3/8] framework: create independent foler for nic modules Yong Liu
2015-12-13  4:57 ` [dts] [PATCH 4/8] nics: add fm10k module for RedRockCanYou family nic Yong Liu
2015-12-13  4:57 ` [dts] [PATCH 5/8] framework: net device object get from net_device module Yong Liu
2015-12-13  4:57 ` [dts] [PATCH 6/8] framework dts: close netdevice related session after exit Yong Liu
2015-12-13  4:57 ` [dts] [PATCH 7/8] conf: add sample for RedRockCanYou family nic Yong Liu
2015-12-13  4:57 ` [dts] [PATCH 8/8] framework project_dpdk: add extra setup after bind driver Yong Liu
2015-12-14  1:34 ` [dts] [RFC PATCH 0/8] support fm10k family nics Liu, Yong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).