aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yardstick/network_services/libs/ixia_libs/ixnet/ixnet_api.py68
-rw-r--r--yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py41
2 files changed, 109 insertions, 0 deletions
diff --git a/yardstick/network_services/libs/ixia_libs/ixnet/ixnet_api.py b/yardstick/network_services/libs/ixia_libs/ixnet/ixnet_api.py
index 1428c38f4..12f081dc6 100644
--- a/yardstick/network_services/libs/ixia_libs/ixnet/ixnet_api.py
+++ b/yardstick/network_services/libs/ixia_libs/ixnet/ixnet_api.py
@@ -50,6 +50,20 @@ TRAFFIC_STATUS_STOPPED = 'stopped'
SUPPORTED_PROTO = [PROTO_UDP]
+class Vlan(object):
+ def __init__(self,
+ vlan_id, vlan_id_step=None, vlan_id_direction='increment',
+ prio=None, prio_step=None, prio_direction='increment',
+ tp_id=None):
+ self.vlan_id = vlan_id
+ self.vlan_id_step = vlan_id_step
+ self.vlan_id_direction = vlan_id_direction
+ self.prio = prio
+ self.prio_step = prio_step
+ self.prio_direction = prio_direction
+ self.tp_id = tp_id
+
+
# NOTE(ralonsoh): this pragma will be removed in the last patch of this series
class IxNextgen(object): # pragma: no cover
@@ -618,6 +632,60 @@ class IxNextgen(object): # pragma: no cover
self.ixnet.commit()
return obj
+ def _create_vlans(self, ethernet, count):
+ self.ixnet.setMultiAttribute(ethernet, '-useVlans', 'true')
+ self.ixnet.setMultiAttribute(ethernet, '-vlanCount', count)
+ self.ixnet.commit()
+
+ def _configure_vlans(self, ethernet, vlans):
+ vlans_obj = self.ixnet.getList(ethernet, 'vlan')
+ for i, vlan_obj in enumerate(vlans_obj):
+ if vlans[i].vlan_id_step is not None:
+ vlan_id_obj = self.ixnet.getAttribute(vlan_obj, '-vlanId')
+ self.ixnet.setMultiAttribute(vlan_id_obj, '-clearOverlays',
+ 'true', '-pattern', 'counter')
+ vlan_id_counter = self.ixnet.add(vlan_id_obj, 'counter')
+ self.ixnet.setMultiAttribute(vlan_id_counter, '-start',
+ vlans[i].vlan_id, '-step',
+ vlans[i].vlan_id_step,
+ '-direction',
+ vlans[i].vlan_id_direction)
+ else:
+ vlan_id_obj = self.ixnet.getAttribute(vlan_obj, '-vlanId')
+ self.ixnet.setMultiAttribute(vlan_id_obj + '/singleValue',
+ '-value', vlans[i].vlan_id)
+
+ if vlans[i].prio_step is not None:
+ prio_obj = self.ixnet.getAttribute(vlan_obj, '-priority')
+ self.ixnet.setMultiAttribute(prio_obj, '-clearOverlays', 'true',
+ '-pattern', 'counter')
+ prio_counter = self.ixnet.add(prio_obj, 'counter')
+ self.ixnet.setMultiAttribute(prio_counter,
+ '-start', vlans[i].prio,
+ '-step', vlans[i].prio_step,
+ '-direction', vlans[i].prio_direction)
+ elif vlans[i].prio is not None:
+ prio_obj = self.ixnet.getAttribute(vlan_obj, '-priority')
+ self.ixnet.setMultiAttribute(prio_obj + '/singleValue',
+ '-value', vlans[i].prio)
+
+ if vlans[i].tp_id is not None:
+ tp_id_obj = self.ixnet.getAttribute(vlan_obj, '-tpid')
+ self.ixnet.setMultiAttribute(tp_id_obj + '/singleValue',
+ '-value', vlans[i].tp_id)
+
+ self.ixnet.commit()
+
+ def add_vlans(self, ethernet, vlans):
+ log.debug("add_vlans: ethernet='%s'", ethernet)
+
+ if vlans is None or len(vlans) == 0:
+ raise RuntimeError(
+ "Invalid 'vlans' argument. Expected list of Vlan instances.")
+
+ self._create_vlans(ethernet, len(vlans))
+ self._configure_vlans(ethernet, vlans)
+
def add_ipv4(self, ethernet, name='',
addr=None, addr_step=None, addr_direction='increment',
prefix=None, prefix_step=None, prefix_direction='increment',
diff --git a/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py b/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py
index 3077e3c17..4e3199a83 100644
--- a/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py
+++ b/yardstick/tests/unit/network_services/libs/ixia_libs/test_ixnet_api.py
@@ -212,6 +212,47 @@ class TestIxNextgen(unittest.TestCase):
'obj', '-name', 'ethernet 1')
self.ixnet_gen.ixnet.commit.assert_called_once()
+ def test_add_vlans_single(self):
+ obj = 'ethernet'
+ self.ixnet_gen.ixnet.getAttribute.return_value = 'attr'
+ self.ixnet_gen.ixnet.getList.return_value = ['vlan1', 'vlan2']
+ vlan1 = ixnet_api.Vlan(vlan_id=100, tp_id='ethertype88a8', prio=2)
+ vlan2 = ixnet_api.Vlan(vlan_id=101, tp_id='ethertype88a8', prio=3)
+ self.ixnet_gen.add_vlans(obj, [vlan1, vlan2])
+ self.ixnet_gen.ixnet.setMultiAttribute.assert_any_call('ethernet',
+ '-vlanCount', 2)
+ self.ixnet_gen.ixnet.setMultiAttribute.assert_any_call('attr/singleValue',
+ '-value', 100)
+ self.ixnet_gen.ixnet.setMultiAttribute.assert_any_call('attr/singleValue',
+ '-value', 101)
+ self.ixnet_gen.ixnet.setMultiAttribute.assert_any_call('attr/singleValue',
+ '-value', 2)
+ self.ixnet_gen.ixnet.setMultiAttribute.assert_any_call('attr/singleValue',
+ '-value', 3)
+ self.ixnet_gen.ixnet.setMultiAttribute.assert_any_call(
+ 'attr/singleValue', '-value', 'ethertype88a8')
+ self.assertEqual(self.ixnet.commit.call_count, 2)
+
+ def test_add_vlans_increment(self):
+ obj = 'ethernet'
+ self.ixnet_gen.ixnet.add.return_value = 'obj'
+ self.ixnet_gen.ixnet.getAttribute.return_value = 'attr'
+ self.ixnet_gen.ixnet.getList.return_value = ['vlan1']
+ vlan = ixnet_api.Vlan(vlan_id=100, vlan_id_step=1, prio=3, prio_step=2)
+ self.ixnet_gen.add_vlans(obj, [vlan])
+ self.ixnet.setMultiAttribute.assert_any_call('obj', '-start', 100,
+ '-step', 1,
+ '-direction', 'increment')
+ self.ixnet.setMultiAttribute.assert_any_call('obj', '-start', 3,
+ '-step', 2,
+ '-direction', 'increment')
+
+ self.assertEqual(self.ixnet.commit.call_count, 2)
+
+ def test_add_vlans_invalid(self):
+ vlans = []
+ self.assertRaises(RuntimeError, self.ixnet_gen.add_vlans, 'obj', vlans)
+
def test_add_ipv4(self):
self.ixnet_gen.ixnet.add.return_value = 'obj'
self.ixnet_gen.add_ipv4('ethernet 1', name='ipv4 1')