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)