def test_ipv6_to_int_with_shortcut(self): ipv6_str = '3f:10::1:2' val = 0x003f0010000000000000000000010002 res = ip.ipv6_to_int(ipv6_str) eq_(val, res)
def test_ipv6_to_int(self): ipv6_str = '2013:da8:215:8f2:aa20:66ff:fe4c:9c3c' val = 0x20130da8021508f2aa2066fffe4c9c3c res = ip.ipv6_to_int(ipv6_str) eq_(val, res)
def match(flow, pkt, in_port, ofp, in_phy_port=None): """ Args: flow: pkt: in_port: ofp: in_phy_port: Returns: """ eth = pkt[0] vlan = pkt[1] print flow if 'in_port' in flow: if flow['in_port'] != in_port: return False if 'in_phy_port' in flow: if flow['in_phy_port'] != in_phy_port: return False if 'eth_dst' in flow: eth_dst = flow['eth_dst'] if isinstance(eth_dst, tuple): edst, mask = map(mac.haddr_to_int, eth_dst) if edst & mask != mac.haddr_to_int(eth.dst) & mask: return False else: if eth_dst != eth.dst: return False if 'eth_src' in flow: eth_src = flow['eth_src'] if isinstance(eth_src, tuple): esrc, mask = map(mac.haddr_to_int, eth_src) if esrc & mask != mac.haddr_to_int(eth.src) & mask: return False else: if eth_src != eth.src: return False if 'eth_type' in flow: if flow['eth_type'] != vlan.ethertype: return False def test_vid(vid): if vid == ofp.OFPVID_NONE and vlan.vid: return False if vid != vlan.vid | ofp.OFPVID_PRESENT: return False return True if 'vlan_vid' in flow: vlan_vid = flow['vlan_vid'] if isinstance(vlan_vid, tuple): vid, mask = vlan_vid if vid == mask == ofp.OFPVID_PRESENT and not vlan.vid: return False else: test_vid(vid) else: vid = vlan_vid if not test_vid(vid): return False if 'vlan_pcp' in flow: if flow['vlan_pcp'] != vlan.vid: return False ip_dscp = None ip_ecn = None ip_proto = None if vlan.ethertype == 0x0800: ip4 = pkt[2] tp = pkt[3] ip_dscp = ip4.tos >> 2 ip_ecn = ip4.tos & 0x03 ip_proto = ip4.proto if 'ipv4_src' in flow: ipv4_src = flow['ipv4_src'] if isinstance(ipv4_src, tuple): ipsrc, mask = map(ip.ipv4_to_int, ipv4_src) if ipsrc & mask != ip.ipv4_to_int(ip4.src) & mask: return False else: if ipv4_src != ip4.src: return False if 'ipv4_dst' in flow: ipv4_dst = flow['ipv4_dst'] if isinstance(ipv4_dst, tuple): ipsrc, mask = map(ip.ipv4_to_int, ipv4_dst) if ipsrc & mask != ip.ipv4_to_int(ip4.dst) & mask: return False else: if ipv4_dst != ip4.dst: return False if vlan.ethertype == 0x86dd: ip6 = pkt[2] tp = pkt[3] ip_dscp = ip6.traffic_class >> 2 ip_ecn = ip6.traffic_class & 0x03 ip_proto = ip6.nxt if 'ipv6_src' in flow: ipv6_src = flow['ipv6_src'] if isinstance(ipv6_src, tuple): ipsrc, mask = map(ip.ipv6_to_int, ipv6_src) if ipsrc & mask != ip.ipv6_to_int(ip6.src) & mask: return False else: if ipv6_src != ip6.src: return False if 'ipv6_dst' in flow: ipv6_dst = flow['ipv64_dst'] if isinstance(ipv6_dst, tuple): ipsrc, mask = map(ip.ipv6_to_int, ipv6_dst) if ipsrc & mask != ip.ipv6_to_int(ip6.dst) & mask: return False else: if ipv6_dst != ip6.dst: return False if 'ip_dscp' in flow and ip_dscp is not None: if flow['ip_dscp'] != ip_dscp: return False if 'ip_ecn' in flow and ip_ecn is not None: if flow['ip_ecn'] != ip_ecn: return False if 'ip_proto' in flow and ip_proto is not None: if flow['ip_proto'] != ip_proto: return False if ip_proto == 6: # TCP if 'tcp_src' in flow: if flow['tcp_src'] != tp.src_port: return False if 'tcp_dst' in flow: if flow['tcp_dst'] != tp.dst_port: return False if ip_proto == 17: # UDP if 'udp_src' in flow: if flow['udp_src'] != tp.src_port: return False if 'udp_dst' in flow: if flow['udp_dst'] != tp.dst_port: return False if ip_proto == 132: # SCTP if 'sctp_src' in flow: if flow['sctp_src'] != tp.src_port: return False if 'sctp_dst' in flow: if flow['sctp_dst'] != tp.dst_port: return False return True