def create_from_packed(cls, packed): version = None if cls.VERSION in packed: version = packed[cls.VERSION] matches = [] for match in packed[cls.MATCHES]: matches.append(OFPFlowMatch.create_from_packed(match)) edge_actions = {} for node_id, basic_flow_actions in packed[cls.EDGE_ACTIONS].items(): flow_action_list = [] for flow_action in basic_flow_actions: flow_action_list.append(globals()[flow_action[FlowAction.TYPE]].create_from_packed(flow_action)) edge_actions[node_id] = flow_action_list return cls( packed[cls.TYPE], version, packed[cls.FLOW_ID], packed[cls.OWNER], packed[cls.ENABLED], packed[cls.PRIORITY], packed[cls.STATUS], packed[cls.ATTRIBUTES], matches, packed[cls.IDLE_TIMEOUT], packed[cls.HARD_TIMEOUT], packed[cls.PATH], edge_actions, )
def test_create_from_packed_None(self): self.value = {OFPFlowMatch.TYPE: "OFPFlowMatch", OFPFlowMatch.IN_NODE: "0456", OFPFlowMatch.IN_PORT: "0789"} self.result = OFPFlowMatch.create_from_packed(self.value) self.assertEqual(self.result._body, {OFPFlowMatch.TYPE: "OFPFlowMatch", OFPFlowMatch.IN_NODE: "0456", OFPFlowMatch.IN_PORT: "0789"})
def create_from_packed(cls, packed): ports = None ports_except = None if packed[cls.PORTS] is not None: ports = packed[cls.PORTS] ports_except = None else: ports_except = packed[cls.PORTS_EXCEPT] ports = None return cls(packed[cls.PACKET_ID], packed[cls.TYPE], packed[cls.ATTRIBUTES], packed[cls.NODE], ports, ports_except, OFPFlowMatch.create_from_packed(packed[cls.HEADER]), packed[cls.DATA])
def test_create_from_packed(self): flow_val = {OFPFlowMatch.TYPE: "OFPFlowMatch", OFPFlowMatch.IN_NODE: "0456", OFPFlowMatch.IN_PORT: "0789"} self.value = {self.target.TYPE: "OFPFlowActionSetField", self.target.MATCH: flow_val} self.result = OFPFlowActionSetField.create_from_packed(self.value) self.assertEqual(self.result._body[self.target.TYPE], "OFPFlowActionSetField") flow = self.result._body[self.target.MATCH] cmp_flow = OFPFlowMatch.create_from_packed(flow_val) self.assertEqual(flow.type, cmp_flow.type) self.assertEqual(flow.in_node, cmp_flow.in_node) self.assertEqual(flow.in_port, cmp_flow.in_port)
def test_create_from_packed_Not_None(self): self.value = { OFPFlowMatch.TYPE: "OFPFlowMatch", OFPFlowMatch.IN_NODE: "ofp_in_node", OFPFlowMatch.IN_PORT: "ofp_in_port", OFPFlowMatch.IN_PHY_PORT: "in_phy_port", OFPFlowMatch.METADATA: 11, OFPFlowMatch.METADATA_MASK: 12, OFPFlowMatch.ETH_SRC: "eth_src", OFPFlowMatch.ETH_SRC_MASK: "eth_src_mask", OFPFlowMatch.ETH_DST: "eth_dst", OFPFlowMatch.ETH_DST_MASK: "eth_dst_mask", OFPFlowMatch.VLAN_VID: 13, OFPFlowMatch.VLAN_VID_MASK: 14, OFPFlowMatch.VLAN_PCP: 15, OFPFlowMatch.ETH_TYPE: 16, OFPFlowMatch.IP_DSCP: 21, OFPFlowMatch.IP_ECN: 22, OFPFlowMatch.IP_PROTO: 23, OFPFlowMatch.IPV4_SRC: "ipv4_src", OFPFlowMatch.IPV4_SRC_MASK: "ipv4_src_mask", OFPFlowMatch.IPV4_DST: "ipv4_dst", OFPFlowMatch.IPV4_DST_MASK: "ipv4_dst_mask", OFPFlowMatch.TCP_SRC: 31, OFPFlowMatch.TCP_DST: 32, OFPFlowMatch.UDP_SRC: 33, OFPFlowMatch.UDP_DST: 34, OFPFlowMatch.SCTP_SRC: 35, OFPFlowMatch.SCTP_DST: 36, OFPFlowMatch.ICMPV4_TYPE: 37, OFPFlowMatch.ICMPV4_CODE: 38, OFPFlowMatch.ARP_OP: 40, OFPFlowMatch.ARP_SPA: "arp_spa", OFPFlowMatch.ARP_SPA_MASK: "arp_spa_mask", OFPFlowMatch.ARP_TPA: "arp_tpa", OFPFlowMatch.ARP_TPA_MASK: "arp_tpa_mask", OFPFlowMatch.ARP_SHA: "arp_sha", OFPFlowMatch.ARP_SHA_MASK: "arp_sha_mask", OFPFlowMatch.ARP_THA: "arp_tha", OFPFlowMatch.ARP_THA_MASK: "arp_tha_mask", OFPFlowMatch.IPV6_SRC: "ipv6_src", OFPFlowMatch.IPV6_SRC_MASK: "ipv6_src_mask", OFPFlowMatch.IPV6_DST: "ipv6_dst", OFPFlowMatch.IPV6_DST_MASK: "ipv6_dst_mask", OFPFlowMatch.IPV6_FLABEL: 50, OFPFlowMatch.IPV6_FLABEL_MASK: 51, OFPFlowMatch.ICMPV6_TYPE: 52, OFPFlowMatch.ICMPV6_CODE: 53, OFPFlowMatch.IPV6_ND_TARGET: "ipv6_nd_target", OFPFlowMatch.IPV6_ND_SLL: "ipv6_nd_sll", OFPFlowMatch.IPV6_ND_TLL: "ipv6_nd_tll", OFPFlowMatch.MPLS_LABEL: 54, OFPFlowMatch.MPLS_TC: 55, OFPFlowMatch.MPLS_BOS: 56, OFPFlowMatch.PBB_ISID: 57, OFPFlowMatch.PBB_ISID_MASK: 58, OFPFlowMatch.TUNNEL_ID: 59, OFPFlowMatch.TUNNEL_ID_MASK: 60, OFPFlowMatch.IPV6_EXTHDR: 61, OFPFlowMatch.IPV6_EXTHDR_MASK: 62 } self.result = OFPFlowMatch.create_from_packed(self.value) self.assertEqual(self.result._body[OFPFlowMatch.TYPE], "OFPFlowMatch") self.assertEqual(self.result._body[OFPFlowMatch.IN_NODE], "ofp_in_node") self.assertEqual(self.result._body[OFPFlowMatch.IN_PORT], "ofp_in_port") self.assertEqual(self.result._body[OFPFlowMatch.IN_PHY_PORT], "in_phy_port") self.assertEqual(self.result._body[OFPFlowMatch.METADATA], 11) self.assertEqual(self.result._body[OFPFlowMatch.METADATA_MASK], 12) self.assertEqual(self.result._body[OFPFlowMatch.ETH_SRC], "eth_src") self.assertEqual(self.result._body[OFPFlowMatch.ETH_SRC_MASK], "eth_src_mask") self.assertEqual(self.result._body[OFPFlowMatch.ETH_DST], "eth_dst") self.assertEqual(self.result._body[OFPFlowMatch.ETH_DST_MASK], "eth_dst_mask") self.assertEqual(self.result._body[OFPFlowMatch.VLAN_VID], 13) self.assertEqual(self.result._body[OFPFlowMatch.VLAN_VID_MASK], 14) self.assertEqual(self.result._body[OFPFlowMatch.VLAN_PCP], 15) self.assertEqual(self.result._body[OFPFlowMatch.ETH_TYPE], 16) self.assertEqual(self.result._body[OFPFlowMatch.IP_DSCP], 21) self.assertEqual(self.result._body[OFPFlowMatch.IP_ECN], 22) self.assertEqual(self.result._body[OFPFlowMatch.IP_PROTO], 23) self.assertEqual(self.result._body[OFPFlowMatch.IPV4_SRC], "ipv4_src") self.assertEqual(self.result._body[OFPFlowMatch.IPV4_SRC_MASK], "ipv4_src_mask") self.assertEqual(self.result._body[OFPFlowMatch.IPV4_DST], "ipv4_dst") self.assertEqual(self.result._body[OFPFlowMatch.IPV4_DST_MASK], "ipv4_dst_mask") self.assertEqual(self.result._body[OFPFlowMatch.TCP_SRC], 31) self.assertEqual(self.result._body[OFPFlowMatch.TCP_DST], 32) self.assertEqual(self.result._body[OFPFlowMatch.UDP_SRC], 33) self.assertEqual(self.result._body[OFPFlowMatch.UDP_DST], 34) self.assertEqual(self.result._body[OFPFlowMatch.SCTP_SRC], 35) self.assertEqual(self.result._body[OFPFlowMatch.SCTP_DST], 36) self.assertEqual(self.result._body[OFPFlowMatch.ICMPV4_TYPE], 37) self.assertEqual(self.result._body[OFPFlowMatch.ICMPV4_CODE], 38) self.assertEqual(self.result._body[OFPFlowMatch.ARP_OP], 40) self.assertEqual(self.result._body[OFPFlowMatch.ARP_SPA], "arp_spa") self.assertEqual(self.result._body[OFPFlowMatch.ARP_SPA_MASK], "arp_spa_mask") self.assertEqual(self.result._body[OFPFlowMatch.ARP_TPA], "arp_tpa") self.assertEqual(self.result._body[OFPFlowMatch.ARP_TPA_MASK], "arp_tpa_mask") self.assertEqual(self.result._body[OFPFlowMatch.ARP_SHA], "arp_sha") self.assertEqual(self.result._body[OFPFlowMatch.ARP_SHA_MASK], "arp_sha_mask") self.assertEqual(self.result._body[OFPFlowMatch.ARP_THA], "arp_tha") self.assertEqual(self.result._body[OFPFlowMatch.ARP_THA_MASK], "arp_tha_mask") self.assertEqual(self.result._body[OFPFlowMatch.IPV6_SRC], "ipv6_src") self.assertEqual(self.result._body[OFPFlowMatch.IPV6_SRC_MASK], "ipv6_src_mask") self.assertEqual(self.result._body[OFPFlowMatch.IPV6_DST], "ipv6_dst") self.assertEqual(self.result._body[OFPFlowMatch.IPV6_DST_MASK], "ipv6_dst_mask") self.assertEqual(self.result._body[OFPFlowMatch.IPV6_FLABEL], 50) self.assertEqual(self.result._body[OFPFlowMatch.IPV6_FLABEL_MASK], 51) self.assertEqual(self.result._body[OFPFlowMatch.ICMPV6_TYPE], 52) self.assertEqual(self.result._body[OFPFlowMatch.ICMPV6_CODE], 53) self.assertEqual(self.result._body[OFPFlowMatch.IPV6_ND_TARGET], "ipv6_nd_target") self.assertEqual(self.result._body[OFPFlowMatch.IPV6_ND_SLL], "ipv6_nd_sll") self.assertEqual(self.result._body[OFPFlowMatch.IPV6_ND_TLL], "ipv6_nd_tll") self.assertEqual(self.result._body[OFPFlowMatch.MPLS_LABEL], 54) self.assertEqual(self.result._body[OFPFlowMatch.MPLS_TC], 55) self.assertEqual(self.result._body[OFPFlowMatch.MPLS_BOS], 56) self.assertEqual(self.result._body[OFPFlowMatch.PBB_ISID], 57) self.assertEqual(self.result._body[OFPFlowMatch.PBB_ISID_MASK], 58) self.assertEqual(self.result._body[OFPFlowMatch.TUNNEL_ID], 59) self.assertEqual(self.result._body[OFPFlowMatch.TUNNEL_ID_MASK], 60) self.assertEqual(self.result._body[OFPFlowMatch.IPV6_EXTHDR], 61) self.assertEqual(self.result._body[OFPFlowMatch.IPV6_EXTHDR_MASK], 62)
def create_from_packed(cls, packed): return cls(packed[cls.PACKET_ID], packed[cls.TYPE], packed[cls.ATTRIBUTES], packed[cls.NODE], packed[cls.PORT], OFPFlowMatch.create_from_packed(packed[cls.HEADER]), packed[cls.DATA])
def create_from_packed(cls, packed): return cls(packed[cls.PACKET_ID], packed[cls.TYPE], packed[cls.ATTRIBUTES], packed[cls.NODE], packed[cls.PORT], OFPFlowMatch.create_from_packed(packed[cls.HEADER]), packed[cls.DATA])
def create_from_packed(cls, packed): return cls(packed[cls.TYPE], OFPFlowMatch.create_from_packed(packed[cls.MATCH]))