def _add_flow(self, flow, port1, port2, reverse_flow=False): """ Helper method to insert flow into the vSwitch """ self._vswitch.add_flow(self._bridge, add_ports_to_flow(flow, port1, port2)) if reverse_flow: self._vswitch.add_flow(self._bridge, add_ports_to_flow(flow, port2, port1))
def _setup_decap(self): """ Sets up the switch for overlay P2P decapsulation test """ self._logger.debug('Setup using %s', str(self._vswitch_class)) try: self._vswitch.start() bridge = S.getValue('TUNNEL_INTEGRATION_BRIDGE') bridge_ext = S.getValue('TUNNEL_EXTERNAL_BRIDGE') bridge_ext_ip = S.getValue('TUNNEL_EXTERNAL_BRIDGE_IP') tgen_ip1 = S.getValue('TRAFFICGEN_PORT1_IP') self._vswitch.add_switch(bridge) tasks.run_task(['sudo', 'ip', 'addr', 'add', S.getValue('VTEP_IP1'), 'dev', bridge], self._logger, 'Assign ' + S.getValue('VTEP_IP1') + ' to ' + bridge, False) tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', bridge, 'up'], self._logger, 'Bring up ' + bridge, False) tunnel_type = self._traffic['tunnel_type'] self._vswitch.add_switch(bridge_ext) self._vswitch.add_phy_port(bridge) (_, phy2_number) = self._vswitch.add_phy_port(bridge_ext) if tunnel_type == "vxlan": vxlan_vni = 'options:key=' + S.getValue('VXLAN_VNI') (_, phy3_number) = self._vswitch.add_tunnel_port(bridge_ext, tgen_ip1, tunnel_type, params=[vxlan_vni]) else: (_, phy3_number) = self._vswitch.add_tunnel_port(bridge_ext, tgen_ip1, tunnel_type) tasks.run_task(['sudo', 'ip', 'addr', 'add', bridge_ext_ip, 'dev', bridge_ext], self._logger, 'Assign ' + bridge_ext_ip + ' to ' + bridge_ext) tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', bridge_ext, 'up'], self._logger, 'Set ' + bridge_ext + ' status to up') self._vswitch.set_tunnel_arp(tgen_ip1, S.getValue('TRAFFICGEN_PORT1_MAC'), bridge) # Test is unidirectional for now self._vswitch.del_flow(bridge_ext) flow1 = add_ports_to_flow(S.getValue('OVS_FLOW_TEMPLATE'), phy3_number, phy2_number) self._vswitch.add_flow(bridge_ext, flow1) except: self._vswitch.stop() raise
def _setup_decap(self): """ Sets up the switch for overlay P2P decapsulation test """ self._logger.debug('Setup using ' + str(self._vswitch_class)) try: self._vswitch.start() bridge = settings.getValue('TUNNEL_INTEGRATION_BRIDGE') bridge_ext = settings.getValue('TUNNEL_EXTERNAL_BRIDGE') bridge_ext_ip = settings.getValue('TUNNEL_EXTERNAL_BRIDGE_IP') tgen_ip1 = settings.getValue('TRAFFICGEN_PORT1_IP') self._vswitch.add_switch(bridge) tasks.run_task(['sudo', 'ip', 'addr', 'add', settings.getValue('VTEP_IP1'), 'dev', bridge], self._logger, 'Assign ' + settings.getValue('VTEP_IP1') + ' to ' + bridge, False) tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', bridge, 'up'], self._logger, 'Bring up ' + bridge, False) tunnel_type = self._traffic['tunnel_type'] self._vswitch.add_switch(bridge_ext) self._vswitch.add_phy_port(bridge) (_, phy2_number) = self._vswitch.add_phy_port(bridge_ext) if tunnel_type == "vxlan": vxlan_vni = 'options:key=' + settings.getValue('VXLAN_VNI') (_, phy3_number) = self._vswitch.add_tunnel_port(bridge_ext, tgen_ip1, tunnel_type, params=[vxlan_vni]) else: (_, phy3_number) = self._vswitch.add_tunnel_port(bridge_ext, tgen_ip1, tunnel_type) tasks.run_task(['sudo', 'ip', 'addr', 'add', bridge_ext_ip, 'dev', bridge_ext], self._logger, 'Assign ' + bridge_ext_ip + ' to ' + bridge_ext) tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', bridge_ext, 'up'], self._logger, 'Set ' + bridge_ext + ' status to up') self._vswitch.set_tunnel_arp(tgen_ip1, settings.getValue('TRAFFICGEN_PORT1_MAC'), bridge) # Test is unidirectional for now self._vswitch.del_flow(bridge_ext) flow1 = add_ports_to_flow(_FLOW_TEMPLATE, phy3_number, phy2_number) self._vswitch.add_flow(bridge_ext, flow1) except: self._vswitch.stop() raise
def setup(self): """ Sets up the switch for pvp """ self._logger.debug('Setup using ' + str(self._vswitch_class)) try: self._vswitch.start() bridge = settings.getValue('VSWITCH_BRIDGE_NAME') self._vswitch.add_switch(bridge) (_, phy1_number) = self._vswitch.add_phy_port(bridge) (_, phy2_number) = self._vswitch.add_phy_port(bridge) (_, vport1_number) = self._vswitch.add_vport(bridge) (_, vport2_number) = self._vswitch.add_vport(bridge) self._vswitch.del_flow(bridge) # configure flows according to the TC definition flow_template = _FLOW_TEMPLATE.copy() if self._traffic['flow_type'] == 'IP': flow_template.update({ 'dl_type': '0x0800', 'nw_src': self._traffic['l3']['srcip'], 'nw_dst': self._traffic['l3']['dstip'] }) flow1 = add_ports_to_flow(flow_template, phy1_number, vport1_number) flow2 = add_ports_to_flow(flow_template, vport2_number, phy2_number) self._vswitch.add_flow(bridge, flow1) self._vswitch.add_flow(bridge, flow2) if self._traffic['bidir']: flow3 = add_ports_to_flow(flow_template, phy2_number, vport2_number) flow4 = add_ports_to_flow(flow_template, vport1_number, phy1_number) self._vswitch.add_flow(bridge, flow3) self._vswitch.add_flow(bridge, flow4) except: self._vswitch.stop() raise
def setup(self): """ Sets up the switch for pvp """ self._logger.debug('Setup using ' + str(self._vswitch_class)) try: self._vswitch.start() bridge = settings.getValue('VSWITCH_BRIDGE_NAME') self._vswitch.add_switch(bridge) (_, phy1_number) = self._vswitch.add_phy_port(bridge) (_, phy2_number) = self._vswitch.add_phy_port(bridge) (_, vport1_number) = self._vswitch.add_vport(bridge) (_, vport2_number) = self._vswitch.add_vport(bridge) self._vswitch.del_flow(bridge) # configure flows according to the TC definition flow_template = _FLOW_TEMPLATE.copy() if self._traffic['flow_type'] == 'IP': flow_template.update({'dl_type':'0x0800', 'nw_src':self._traffic['l3']['srcip'], 'nw_dst':self._traffic['l3']['dstip']}) flow1 = add_ports_to_flow(flow_template, phy1_number, vport1_number) flow2 = add_ports_to_flow(flow_template, vport2_number, phy2_number) self._vswitch.add_flow(bridge, flow1) self._vswitch.add_flow(bridge, flow2) if self._traffic['bidir'] == 'True': flow3 = add_ports_to_flow(flow_template, phy2_number, vport2_number) flow4 = add_ports_to_flow(flow_template, vport1_number, phy1_number) self._vswitch.add_flow(bridge, flow3) self._vswitch.add_flow(bridge, flow4) except: self._vswitch.stop() raise
def _setup_encap(self): """ Sets up the switch for overlay P2P encapsulation test Create 2 bridges br0 (integration bridge) and br-ext and a VXLAN port for encapsulation. """ self._logger.debug('Setup using %s', str(self._vswitch_class)) try: self._vswitch.start() bridge = S.getValue('TUNNEL_INTEGRATION_BRIDGE') bridge_ext = S.getValue('TUNNEL_EXTERNAL_BRIDGE') bridge_ext_ip = S.getValue('TUNNEL_EXTERNAL_BRIDGE_IP') tg_port2_mac = S.getValue('TRAFFICGEN_PORT2_MAC') vtep_ip2 = S.getValue('VTEP_IP2') self._vswitch.add_switch(bridge) tasks.run_task(['sudo', 'ip', 'addr', 'add', S.getValue('VTEP_IP1'), 'dev', bridge], self._logger, 'Assign ' + S.getValue('VTEP_IP1') + ' to ' + bridge, False) tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', bridge, 'up'], self._logger, 'Bring up ' + bridge, False) tunnel_type = self._traffic['tunnel_type'] self._vswitch.add_switch(bridge_ext) (_, phy1_number) = self._vswitch.add_phy_port(bridge) (_, phy2_number) = self._vswitch.add_tunnel_port(bridge, vtep_ip2, tunnel_type) self._vswitch.add_phy_port(bridge_ext) tasks.run_task(['sudo', 'ip', 'addr', 'add', bridge_ext_ip, 'dev', bridge_ext], self._logger, 'Assign ' + bridge_ext_ip + ' to ' + bridge_ext) tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', bridge_ext, 'up'], self._logger, 'Set ' + bridge_ext + 'status to up') self._vswitch.add_route(bridge, S.getValue('VTEP_IP2_SUBNET'), bridge_ext) if str(S.getValue('VSWITCH')).endswith('Vanilla'): tasks.run_task(['sudo', 'arp', '-s', vtep_ip2, tg_port2_mac], self._logger, 'Set ' + bridge_ext + ' status to up') else: self._vswitch.set_tunnel_arp(vtep_ip2, tg_port2_mac, bridge_ext) # Test is unidirectional for now self._vswitch.del_flow(bridge) flow1 = add_ports_to_flow(S.getValue('OVS_FLOW_TEMPLATE'), phy1_number, phy2_number) self._vswitch.add_flow(bridge, flow1) # enable MAC learning mode at external bridge flow_ext = S.getValue('OVS_FLOW_TEMPLATE').copy() flow_ext.update({'actions': ['NORMAL']}) self._vswitch.add_flow(bridge_ext, flow_ext) except: self._vswitch.stop() raise
def _setup_vxlan_encap_decap(self): """ Sets up switches for VxLAN overlay P-TUN-P test. Create 2 bridges br-phy1 and br-phy2 (The bridge to connect physical ports. Two more bridges br-mod1 and br-mod2 to mangle and redirect the packets from one tunnel port to other. """ self._logger.debug('Setup using ' + str(self._vswitch_class)) try: self._vswitch.start() self._vswitch.add_switch(self.bridge_phy1) self._vswitch.add_switch(self.bridge_phy2) self._vswitch.add_switch( self.bridge_mod1, params=["other_config:hwaddr=" + self.br_mod_mac1]) self._vswitch.add_switch( self.bridge_mod2, params=["other_config:hwaddr=" + self.br_mod_mac2]) tasks.run_task(['sudo', 'iptables', '-F'], self._logger, 'Clean ip tables', False) tasks.run_task([ 'sudo', 'ip', 'addr', 'add', self.br_mod_ip1, 'dev', self.bridge_mod1 ], self._logger, 'Assign ' + self.br_mod_ip1 + ' to ' + self.bridge_mod1, False) tasks.run_task( ['sudo', 'ip', 'link', 'set', 'dev', self.bridge_mod1, 'up'], self._logger, 'Bring up ' + self.bridge_mod1, False) tasks.run_task([ 'sudo', 'ip', 'addr', 'add', self.br_mod_ip2, 'dev', self.bridge_mod2 ], self._logger, 'Assign ' + self.br_mod_ip2 + ' to ' + self.bridge_mod2, False) tasks.run_task( ['sudo', 'ip', 'link', 'set', 'dev', self.bridge_mod2, 'up'], self._logger, 'Bring up ' + self.bridge_mod2, False) tasks.run_task( ['sudo', 'ip', 'link', 'set', 'dev', self.bridge_phy1, 'up'], self._logger, 'Bring up ' + self.bridge_phy1, False) tasks.run_task( ['sudo', 'ip', 'link', 'set', 'dev', self.bridge_phy2, 'up'], self._logger, 'Bring up ' + self.bridge_phy2, False) self._vswitch.add_route(self.bridge_phy1, self.br_mod_ip1, self.bridge_mod1) self._vswitch.add_route(self.bridge_phy2, self.br_mod_ip2, self.bridge_mod2) # Create tunnel ip and mac from the bridge ips vxlan_local_ip1 = str(IPNetwork(self.br_mod_ip1).ip) vxlan_local_ip2 = str(IPNetwork(self.br_mod_ip2).ip) vxlan_rem_ip1 = str(IPNetwork(self.br_mod_ip1).ip + 1) vxlan_rem_ip2 = str(IPNetwork(self.br_mod_ip2).ip + 1) vxlan_rem_mac1 = EUI(int(EUI(self.br_mod_mac1)) + 1) vxlan_rem_mac1.dialect = mac_unix vxlan_rem_mac2 = EUI(int(EUI(self.br_mod_mac2)) + 1) vxlan_rem_mac2.dialect = mac_unix self._vswitch.set_tunnel_arp(vxlan_local_ip1, self.br_mod_mac1, self.bridge_phy1) self._vswitch.set_tunnel_arp(vxlan_local_ip2, self.br_mod_mac2, self.bridge_phy2) self._vswitch.set_tunnel_arp(vxlan_rem_ip1, str(vxlan_rem_mac1), self.bridge_mod1) self._vswitch.set_tunnel_arp(vxlan_rem_ip2, str(vxlan_rem_mac2), self.bridge_mod2) # Lets add the ports to bridges (_, phy1_number) = self._vswitch.add_phy_port(self.bridge_phy1) (_, phy2_number) = self._vswitch.add_phy_port(self.bridge_phy2) vxlan_vni = 'options:key=' + settings.getValue('VXLAN_VNI') (_, phy3_number) = self._vswitch.add_tunnel_port(self.bridge_phy1, vxlan_rem_ip1, "vxlan", params=[vxlan_vni]) (_, phy4_number) = self._vswitch.add_tunnel_port(self.bridge_phy2, vxlan_rem_ip2, "vxlan", params=[vxlan_vni]) [(_, phy5_number), (_, phy6_number)] = \ self._vswitch.add_veth_pair_port(self.bridge_mod1, self.bridge_mod2) # Set up flows for the switches self._vswitch.del_flow(self.bridge_phy1) self._vswitch.del_flow(self.bridge_phy2) self._vswitch.del_flow(self.bridge_mod1) self._vswitch.del_flow(self.bridge_mod2) flow = add_ports_to_flow(_FLOW_TEMPLATE, phy1_number, phy3_number) self._vswitch.add_flow(self.bridge_phy1, flow) flow = add_ports_to_flow(_FLOW_TEMPLATE, phy3_number, phy1_number) self._vswitch.add_flow(self.bridge_phy1, flow) flow = add_ports_to_flow(_FLOW_TEMPLATE, phy2_number, phy4_number) self._vswitch.add_flow(self.bridge_phy2, flow) flow = add_ports_to_flow(_FLOW_TEMPLATE, phy4_number, phy2_number) self._vswitch.add_flow(self.bridge_phy2, flow) flow = add_ports_to_flow(_FLOW_TEMPLATE, phy5_number, 'LOCAL') self._vswitch.add_flow(self.bridge_mod1, flow) mod_flow_template = _FLOW_TEMPLATE.copy() mod_flow_template.update({ 'ip': '', 'actions': [ 'mod_dl_src:' + str(vxlan_rem_mac2), 'mod_dl_dst:' + self.br_mod_mac2, 'mod_nw_src:' + vxlan_rem_ip2, 'mod_nw_dst:' + vxlan_local_ip2 ] }) flow = add_ports_to_flow(mod_flow_template, 'LOCAL', phy5_number) self._vswitch.add_flow(self.bridge_mod1, flow) flow = add_ports_to_flow(_FLOW_TEMPLATE, phy6_number, 'LOCAL') self._vswitch.add_flow(self.bridge_mod2, flow) mod_flow_template = _FLOW_TEMPLATE.copy() mod_flow_template.update({ 'ip': '', 'actions': [ 'mod_dl_src:' + str(vxlan_rem_mac1), 'mod_dl_dst:' + self.br_mod_mac1, 'mod_nw_src:' + vxlan_rem_ip1, 'mod_nw_dst:' + vxlan_local_ip1 ] }) flow = add_ports_to_flow(mod_flow_template, 'LOCAL', phy6_number) self._vswitch.add_flow(self.bridge_mod2, flow) except: self._vswitch.stop() raise
def _setup_encap(self): """ Sets up the switch for overlay P2P encapsulation test Create 2 bridges br0 (integration bridge) and br-ext and a VXLAN port for encapsulation. """ self._logger.debug('Setup using ' + str(self._vswitch_class)) try: self._vswitch.start() bridge = settings.getValue('TUNNEL_INTEGRATION_BRIDGE') bridge_ext = settings.getValue('TUNNEL_EXTERNAL_BRIDGE') bridge_ext_ip = settings.getValue('TUNNEL_EXTERNAL_BRIDGE_IP') tg_port2_mac = settings.getValue('TRAFFICGEN_PORT2_MAC') vtep_ip2 = settings.getValue('VTEP_IP2') self._vswitch.add_switch(bridge) tasks.run_task(['sudo', 'ifconfig', bridge, settings.getValue('VTEP_IP1')], self._logger, 'Assign ' + settings.getValue('VTEP_IP1') + ' to ' + bridge, False) tunnel_type = self._traffic['tunnel_type'] self._vswitch.add_switch(bridge_ext) (_, phy1_number) = self._vswitch.add_phy_port(bridge) (_, phy2_number) = self._vswitch.add_tunnel_port(bridge, vtep_ip2, tunnel_type) self._vswitch.add_phy_port(bridge_ext) tasks.run_task(['sudo', 'ip', 'addr', 'add', bridge_ext_ip, 'dev', bridge_ext], self._logger, 'Assign ' + bridge_ext_ip + ' to ' + bridge_ext) tasks.run_task(['sudo', 'ip', 'link', 'set', 'dev', bridge_ext, 'up'], self._logger, 'Set ' + bridge_ext + 'status to up') self._vswitch.add_route(bridge, settings.getValue('VTEP_IP2_SUBNET'), bridge_ext) if settings.getValue('VSWITCH').endswith('Vanilla'): tasks.run_task(['sudo', 'arp', '-s', vtep_ip2, tg_port2_mac], self._logger, 'Set ' + bridge_ext + ' status to up') else: self._vswitch.set_tunnel_arp(vtep_ip2, tg_port2_mac, bridge_ext) # Test is unidirectional for now self._vswitch.del_flow(bridge) flow1 = add_ports_to_flow(_FLOW_TEMPLATE, phy1_number, phy2_number) self._vswitch.add_flow(bridge, flow1) except: self._vswitch.stop() raise