def process_packet(self, in_port, packet): """ @param in_port The ingress port number on which packet arrived @param packet A bytearray with the packet data """ buf = bytearray(packet) for idx in range((len(packet) + 19)/20): logging.debug(hexify(buf[20*idx : 20*(idx+1)], 20)) if self.disabled: logging.debug("Switch is disabled; discarding packet") return parsed_packet = ParsedPacket(buf, self.metadata) logging.debug("Processing packet %d from port %d with %s" % (parsed_packet.id, in_port, self.first_processor.name)) self.first_processor.process(parsed_packet)
from parsed_packet import ParsedPacket # Create IRI config from unit_test if len(sys.argv) > 2: unit_test_input = sys.argv[2:] else: local_dir = os.path.dirname(os.path.abspath(__file__)) unit_test_input = local_dir + "/../unit_test.yml" logging.info("Using input file %s" % unit_test_input) iri = IriInstance("instance", unit_test_input, transmit_packet) parser = iri.iri_parser["parser"] # Test cases for unit test input byte_buf = bytearray(range(100)) ppkt = ParsedPacket(byte_buf, {}) parser.process(ppkt) if "ethernet" in iri.header.keys(): air_assert(ppkt.header_length == 14, "Did not parser ether hdr") air_assert("ethernet" in ppkt.header_map.keys(), "Did not parser ether hdr") air_assert(ppkt.get_field("ethernet"), "Failed ethernet header valid check") air_assert(not ppkt.get_field("foo"), "Failed negative foo header valid check") byte_buf[12] = 0x81 byte_buf[13] = 0 ppkt = ParsedPacket(byte_buf, {}) parser.process(ppkt)
from pif_ir.air.instance import AirInstance from parsed_packet import ParsedPacket # Set up the unit test AIR instance local_dir = os.path.dirname(os.path.abspath(__file__)) iri = AirInstance("instance", local_dir + "/../tests/unit_test.yml", transmit_handler) exact_entry = TableEntryExact({"ethernet.ethertype": 0x07}, "some_action", {}) ternary_entry = TableEntryTernary({"ethernet.ethertype": 0x07}, {"ethernet.ethertype": 0x07}, "some_action", {}, 17) default_entry = TableEntryDefault("some_action", {}) byte_buf = bytearray(range(100)) ppkt = ParsedPacket(byte_buf, {}) meta_ir_assert(exact_entry.check_match(ppkt) is None, "Exact non-match") meta_ir_assert( ternary_entry.check_match(ppkt) is None, "Ternary non-match") ppkt.parse_header("ethernet", iri.meta_ir_object_map["ethernet"]) ppkt.set_field("ethernet.ethertype", 0x17) match_val = ternary_entry.check_match(ppkt) meta_ir_assert(match_val is not None, "Ternary should match post set") match_val = exact_entry.check_match(ppkt) meta_ir_assert(match_val is None, "Exact should not match post set")
logging.debug("Pipeline %s, pkt %d: calling to %s", self.name, parsed_packet.id, self.next_processor.name) self.next_processor.process(parsed_packet) ################################################################ if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG, filename=sys.argv[1]) logging.info("RUNNING MODULE: %s" % __file__) def transmit_packet(out_port, packet): pass from pif_ir.air.instance import AirInstance from parsed_packet import ParsedPacket # Create AIR config from unit_test local_dir = os.path.dirname(os.path.abspath(__file__)) iri = AirInstance("instance", local_dir + "/../tests/unit_test.yml", transmit_packet) # Instantiate the ingress_flow pipe pipe = iri.air_pipeline["ingress_flow"] # Create a packet object byte_buf = bytearray(range(100)) ppkt = ParsedPacket(byte_buf, {})
from parsed_packet import ParsedPacket # Set up the unit test IRI instance local_dir = os.path.dirname(os.path.abspath(__file__)) iri = IriInstance("instance", local_dir + "/../unit_test.yml", transmit_handler) exact_entry = TableEntryExact({"ethernet.ethertype" : 0x07}, "some_action", {}) ternary_entry = TableEntryTernary({"ethernet.ethertype" : 0x07}, {"ethernet.ethertype" : 0x07}, "some_action", {}, 17) default_entry = TableEntryDefault("some_action", {}) byte_buf = bytearray(range(100)) ppkt = ParsedPacket(byte_buf, {}) air_assert(exact_entry.check_match(ppkt) is None, "Exact non-match") air_assert(ternary_entry.check_match(ppkt) is None, "Ternary non-match") ppkt.parse_header("ethernet", iri.air_object_map["ethernet"]) ppkt.set_field("ethernet.ethertype", 0x17) match_val = ternary_entry.check_match(ppkt) air_assert(match_val is not None, "Ternary should match post set") match_val = exact_entry.check_match(ppkt) air_assert(match_val is None, "Exact should not match post set")