X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Fvpp_ip_route.py;h=9d6bfb77d9333f3eca0cb72da700277382b6115e;hb=refs%2Fchanges%2F09%2F14709%2F8;hp=39b2b1ae1e84c6d6cdfd3bbd8871b7dc64dfdeff;hpb=2303cb181b51f63c909cd506125c1f832432865a;p=vpp.git diff --git a/test/vpp_ip_route.py b/test/vpp_ip_route.py index 39b2b1ae1e8..9d6bfb77d93 100644 --- a/test/vpp_ip_route.py +++ b/test/vpp_ip_route.py @@ -6,6 +6,7 @@ from vpp_object import * from socket import inet_pton, inet_ntop, AF_INET, AF_INET6 +from vpp_ip import * # from vnet/vnet/mpls/mpls_types.h MPLS_IETF_MAX_LABEL = 0xfffff @@ -29,15 +30,6 @@ class MRouteEntryFlags: MFIB_ENTRY_FLAG_INHERIT_ACCEPT = 8 -class DpoProto: - DPO_PROTO_IP4 = 0 - DPO_PROTO_IP6 = 1 - DPO_PROTO_MPLS = 2 - DPO_PROTO_ETHERNET = 3 - DPO_PROTO_BIER = 4 - DPO_PROTO_NSH = 5 - - class MplsLspMode: PIPE = 0 UNIFORM = 1 @@ -60,6 +52,25 @@ def find_route(test, ip_addr, len, table_id=0, inet=AF_INET): return False +def find_mroute(test, grp_addr, src_addr, grp_addr_len, + table_id=0, inet=AF_INET): + if inet == AF_INET: + s = 4 + routes = test.vapi.ip_mfib_dump() + else: + s = 16 + routes = test.vapi.ip6_mfib_dump() + gaddr = inet_pton(inet, grp_addr) + saddr = inet_pton(inet, src_addr) + for e in routes: + if gaddr == e.grp_address[:s] \ + and grp_addr_len == e.address_length \ + and saddr == e.src_address[:s] \ + and table_id == e.table_id: + return True + return False + + class VppIpTable(VppObject): def __init__(self, @@ -185,12 +196,14 @@ class VppRoutePath(object): class VppMRoutePath(VppRoutePath): def __init__(self, nh_sw_if_index, flags, + nh=None, proto=DpoProto.DPO_PROTO_IP4, bier_imp=0): - super(VppMRoutePath, self).__init__( - "::" if proto is DpoProto.DPO_PROTO_IP6 else "0.0.0.0", - nh_sw_if_index, - proto=proto) + if not nh: + nh = "::" if proto is DpoProto.DPO_PROTO_IP6 else "0.0.0.0" + super(VppMRoutePath, self).__init__(nh, + nh_sw_if_index, + proto=proto) self.nh_i_flags = flags self.bier_imp = bier_imp @@ -202,7 +215,7 @@ class VppIpRoute(VppObject): def __init__(self, test, dest_addr, dest_addr_len, paths, table_id=0, is_ip6=0, is_local=0, - is_unreach=0, is_prohibit=0): + is_unreach=0, is_prohibit=0, is_drop=0): self._test = test self.paths = paths self.dest_addr_len = dest_addr_len @@ -211,6 +224,7 @@ class VppIpRoute(VppObject): self.is_local = is_local self.is_unreach = is_unreach self.is_prohibit = is_prohibit + self.is_drop = is_drop self.dest_addr_p = dest_addr if is_ip6: self.dest_addr = inet_pton(AF_INET6, dest_addr) @@ -225,7 +239,8 @@ class VppIpRoute(VppObject): self.is_prohibit = is_prohibit def add_vpp_config(self): - if self.is_local or self.is_unreach or self.is_prohibit: + if self.is_local or self.is_unreach or \ + self.is_prohibit or self.is_drop: self._test.vapi.ip_add_del_route( self.dest_addr, self.dest_addr_len, @@ -234,6 +249,7 @@ class VppIpRoute(VppObject): is_local=self.is_local, is_unreach=self.is_unreach, is_prohibit=self.is_prohibit, + is_drop=self.is_drop, table_id=self.table_id, is_ipv6=self.is_ip6) else: @@ -261,7 +277,8 @@ class VppIpRoute(VppObject): self._test.registry.register(self, self._test.logger) def remove_vpp_config(self): - if self.is_local or self.is_unreach or self.is_prohibit: + if self.is_local or self.is_unreach or \ + self.is_prohibit or self.is_drop: self._test.vapi.ip_add_del_route( self.dest_addr, self.dest_addr_len, @@ -322,6 +339,8 @@ class VppIpMRoute(VppObject): self.is_ip6 = is_ip6 self.rpf_id = rpf_id + self.grp_addr_p = grp_addr + self.src_addr_p = src_addr if is_ip6: self.grp_addr = inet_pton(AF_INET6, grp_addr) self.src_addr = inet_pton(AF_INET6, src_addr) @@ -337,6 +356,7 @@ class VppIpMRoute(VppObject): self.e_flags, path.proto, path.nh_itf, + path.nh_addr, path.nh_i_flags, bier_imp=path.bier_imp, rpf_id=self.rpf_id, @@ -352,6 +372,7 @@ class VppIpMRoute(VppObject): self.e_flags, path.proto, path.nh_itf, + path.nh_addr, path.nh_i_flags, table_id=self.table_id, bier_imp=path.bier_imp, @@ -366,6 +387,7 @@ class VppIpMRoute(VppObject): self.e_flags, 0, 0xffffffff, + "", 0, table_id=self.table_id, is_ipv6=self.is_ip6) @@ -378,6 +400,7 @@ class VppIpMRoute(VppObject): self.e_flags, 0, 0xffffffff, + "", 0, rpf_id=self.rpf_id, table_id=self.table_id, @@ -394,22 +417,18 @@ class VppIpMRoute(VppObject): self.e_flags, path.proto, path.nh_itf, + path.nh_addr, path.nh_i_flags, table_id=self.table_id, is_ipv6=self.is_ip6) def query_vpp_config(self): - if self.is_ip6: - dump = self._test.vapi.ip6_mfib_dump() - else: - dump = self._test.vapi.ip_mfib_dump() - for e in dump: - if self.grp_addr == e.grp_address \ - and self.grp_addr_len == e.address_length \ - and self.src_addr == e.src_address \ - and self.table_id == e.table_id: - return True - return False + return find_mroute(self._test, + self.grp_addr_p, + self.src_addr_p, + self.grp_addr_len, + self.table_id, + inet=AF_INET6 if self.is_ip6 == 1 else AF_INET) def __str__(self): return self.object_id()