def build_arp_config(port): dpdk_port_num = self.vnfd_helper.port_num(port) interface = self.vnfd_helper.find_interface( name=port)["virtual-interface"] # We must use the dst because we are on the VNF and we need to # reach the TG. dst_port0_ip = ipaddress.ip_interface( six.text_type("%s/%s" % (interface["dst_ip"], interface["netmask"]))) arp_vars = { "port0_dst_ip_hex": ip_to_hex(dst_port0_ip.network.network_address.exploded), "port0_netmask_hex": ip_to_hex(dst_port0_ip.network.netmask.exploded), # this is the port num that contains port0 subnet and next_hop_ip_hex # this is LINKID which should be based on DPDK port number "port_num": dpdk_port_num, # next hop is dst in this case # must be within subnet "next_hop_ip_hex": ip_to_hex(dst_port0_ip.ip.exploded), } return arp_route_tbl_tmpl.format(**arp_vars)
def generate_arp_route_tbl(self): arp_config = [] arp_route_tbl_tmpl = "({port0_dst_ip_hex},{port0_netmask_hex},{port_num}," \ "{next_hop_ip_hex})" for port_pair in self.port_pair_list: for port in port_pair: port_num = int(port[-1]) interface = self.interfaces[port_num] # We must use the dst because we are on the VNF and we need to # reach the TG. dst_port0_ip = \ ipaddress.ip_interface(six.text_type( "%s/%s" % (interface["virtual-interface"]["dst_ip"], interface["virtual-interface"]["netmask"]))) arp_vars = { "port0_dst_ip_hex": ip_to_hex(dst_port0_ip.network.network_address.exploded), "port0_netmask_hex": ip_to_hex(dst_port0_ip.network.netmask.exploded), # this is the port num that contains port0 subnet and next_hop_ip_hex "port_num": port_num, # next hop is dst in this case # must be within subnet "next_hop_ip_hex": ip_to_hex(dst_port0_ip.ip.exploded), } arp_config.append(arp_route_tbl_tmpl.format(**arp_vars)) return ' '.join(arp_config)
def generate_arp_route_tbl(self): arp_config = [] arp_route_tbl_tmpl = "({port0_dst_ip_hex},{port0_netmask_hex},{port_num}," \ "{next_hop_ip_hex})" for port_pair in self.port_pair_list: for port in port_pair: port_num = int(port[-1]) interface = self.interfaces[port_num] # port0_ip = ipaddress.ip_interface(six.text_type( # "%s/%s" % (interface["virtual-interface"]["local_ip"], # interface["virtual-interface"]["netmask"]))) dst_port0_ip = \ ipaddress.ip_interface(six.text_type( "%s/%s" % (interface["virtual-interface"]["dst_ip"], interface["virtual-interface"]["netmask"]))) arp_vars = { "port0_dst_ip_hex": ip_to_hex(dst_port0_ip.ip.exploded), "port0_netmask_hex": ip_to_hex(dst_port0_ip.network.netmask.exploded), "port_num": port_num, # next hop is dst in this case "next_hop_ip_hex": ip_to_hex(dst_port0_ip.ip.exploded), } arp_config.append(arp_route_tbl_tmpl.format(**arp_vars)) return ' '.join(arp_config)
def test_ip_to_hex_negative(self, *args): # NOTE(ralonsoh): check the calls to mocked functions. addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST mask_list = self.GOOD_IP_V4_MASK_STR_LIST value_iter = (''.join(pair) for pair in product(addr_list, mask_list)) for value in chain(value_iter, self.INVALID_IP_ADDRESS_STR_LIST): self.assertEqual(utils.ip_to_hex(value), value)
def generate_prox_lua_file(self): p = OrderedDict() ext_intf = self.vnfd_helper.interfaces lua_param = self.LUA_PARAMETER_NAME for intf in ext_intf: peer = self.LUA_PARAMETER_PEER[lua_param] port_num = intf["virtual-interface"]["dpdk_port_num"] local_ip = intf["local_ip"] dst_ip = intf["dst_ip"] local_ip_hex = ip_to_hex(local_ip, separator=' ') dst_ip_hex = ip_to_hex(dst_ip, separator=' ') p.update([ ("{}_hex_ip_port_{}".format(lua_param, port_num), local_ip_hex), ("{}_ip_port_{}".format(lua_param, port_num), local_ip), ("{}_hex_ip_port_{}".format(peer, port_num), dst_ip_hex), ("{}_ip_port_{}".format(peer, port_num), dst_ip), ]) lua = os.linesep.join(('{}:"{}"'.format(k, v) for k, v in p.items())) return lua
def generate_prox_lua_file(self): p = OrderedDict() all_ports = self.vnfd_helper.port_pairs.all_ports lua_param = self.LUA_PARAMETER_NAME for port_name in all_ports: peer = self.LUA_PARAMETER_PEER[lua_param] port_num = self.vnfd_helper.port_num(port_name) intf = self.vnfd_helper.find_interface(name=port_name) vintf = intf['virtual-interface'] local_ip = vintf["local_ip"] dst_ip = vintf["dst_ip"] local_ip_hex = ip_to_hex(local_ip, separator=' ') dst_ip_hex = ip_to_hex(dst_ip, separator=' ') p.update([ ("{}_hex_ip_port_{}".format(lua_param, port_num), local_ip_hex), ("{}_ip_port_{}".format(lua_param, port_num), local_ip), ("{}_hex_ip_port_{}".format(peer, port_num), dst_ip_hex), ("{}_ip_port_{}".format(peer, port_num), dst_ip), ]) lua = os.linesep.join(('{}:"{}"'.format(k, v) for k, v in p.items())) return lua
def test_ip_to_hex(self): self.assertEqual(utils.ip_to_hex('0.0.0.0'), '00000000') self.assertEqual(utils.ip_to_hex('10.20.30.40'), '0a141e28') self.assertEqual(utils.ip_to_hex('127.0.0.1'), '7f000001') self.assertEqual(utils.ip_to_hex('172.31.90.100'), 'ac1f5a64') self.assertEqual(utils.ip_to_hex('192.168.254.253'), 'c0a8fefd') self.assertEqual(utils.ip_to_hex('255.255.255.255'), 'ffffffff')
def test_ip_to_hex_negative(self, mock_logging): addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST mask_list = self.GOOD_IP_V4_MASK_STR_LIST value_iter = (''.join(pair) for pair in product(addr_list, mask_list)) for value in chain(value_iter, self.INVALID_IP_ADDRESS_STR_LIST): self.assertEqual(utils.ip_to_hex(value), value)
def test_ip_to_hex_v6_ip(self): for value in self.GOOD_IP_V6_ADDRESS_STR_LIST: self.assertEqual(utils.ip_to_hex(value), value)