Example #1
0
class Switch(Thread):
    """
    @brief An IR switch instance

    """
    def __init__(self, name, input, dataplane):
        """
        @param name The name of the switch instance
        @param input A file or file name with the AIR YAML for the switch
        @param dataplane The OFTest dataplane object

        dataplane must provide
          (port_number, packet_buffer, timestamp) = poll(timeout) 
          send(port_number, packet_buffer)
        """
        Thread.__init__(self)

        logging.info("Starting IRI Switch instance %s" % name)
        self.name = name
        self.input = input
        if isinstance(input, list):
            self.input = " ".join(input)
        self.dataplane = dataplane
        self.killed = False
        self.instance = IriInstance(name, input, dataplane.send)
        self.instance.process_table_init()
        self.instance.enable()

        self.start()

    def run(self):
        """
        @brief The thread runner function

        Poll the data plane for packets. When received, parse and process.

        @todo figure out queue threading
        """
        metadata = self.instance.metadata
        logging.info("IR switch %s running with input %s" % (
            self.name, str(self.input)))
        while not self.killed:
            (port_num, pkt, ts) = self.dataplane.poll(timeout=2)
            if pkt:
                logging.debug("Pkt in port %d. len %d, ts %d" %
                              (port_num, len(pkt), ts))
                self.instance.process_packet(port_num, pkt)

        logging.info("Exiting IR switch %s" % self.name)

    def kill(self):
        self.killed = True
        self.dataplane.kill()
        self.instance.kill()
class Switch(Thread):
    """
    @brief An IR switch instance

    """
    def __init__(self, name, input, dataplane):
        """
        @param name The name of the switch instance
        @param input A file or file name with the AIR YAML for the switch
        @param dataplane The OFTest dataplane object

        dataplane must provide
          (port_number, packet_buffer, timestamp) = poll(timeout) 
          send(port_number, packet_buffer)
        """
        Thread.__init__(self)

        logging.info("Starting IRI Switch instance %s" % name)
        self.name = name
        self.input = input
        self.dataplane = dataplane
        self.killed = False
        self.instance = IriInstance(name, input, dataplane.send)
        self.instance.process_table_init()
        self.instance.enable()

        self.start()

    def run(self):
        """
        @brief The thread runner function

        Poll the data plane for packets. When received, parse and process.

        @todo figure out queue threading
        """
        metadata = self.instance.metadata
        logging.info("IR switch %s running with input %s" %
                     (self.name, str(self.input)))
        while not self.killed:
            (port_num, pkt, ts) = self.dataplane.poll(timeout=2)
            if pkt:
                logging.debug("Pkt in port %d. len %d, ts %d" %
                              (port_num, len(pkt), ts))
                self.instance.process_packet(port_num, pkt)

        logging.info("Exiting IR switch %s" % self.name)

    def kill(self):
        self.killed = True
        self.dataplane.kill()
        self.instance.kill()
    def __init__(self, name, input, dataplane):
        """
        @param name The name of the switch instance
        @param input A file or file name with the AIR YAML for the switch
        @param dataplane The OFTest dataplane object

        dataplane must provide
          (port_number, packet_buffer, timestamp) = poll(timeout) 
          send(port_number, packet_buffer)
        """
        Thread.__init__(self)

        logging.info("Starting IRI Switch instance %s" % name)
        self.name = name
        self.input = input
        self.dataplane = dataplane
        self.killed = False
        self.instance = IriInstance(name, input, dataplane.send)
        self.instance.process_table_init()
        self.instance.enable()

        self.start()
Example #4
0
    def __init__(self, name, input, dataplane):
        """
        @param name The name of the switch instance
        @param input A file or file name with the AIR YAML for the switch
        @param dataplane The OFTest dataplane object

        dataplane must provide
          (port_number, packet_buffer, timestamp) = poll(timeout) 
          send(port_number, packet_buffer)
        """
        Thread.__init__(self)

        logging.info("Starting IRI Switch instance %s" % name)
        self.name = name
        self.input = input
        self.dataplane = dataplane
        self.killed = False
        self.instance = IriInstance(name, input, dataplane.send)
        self.instance.process_table_init()
        self.instance.enable()

        self.start()
Example #5
0
    logging.info("RUNNING MODULE: %s" % __file__)

    def transmit_packet(out_port, packet):
        pass

    from instance import IriInstance
    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"),

################################################################

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG, filename=sys.argv[1])
    logging.info("RUNNING MODULE: %s" % __file__)

    from instance import IriInstance

    def transmit_packet(out_port, packet):
        pass

    # Create config from unit_test
    local_dir = os.path.dirname(os.path.abspath(__file__))
    iri = IriInstance("instance", local_dir + "/../unit_test.yml",
                      transmit_packet)

    # Create 100 byte packet
    byte_buf = bytearray(range(100))
    ppkt = ParsedPacket(byte_buf, {})
    air_assert(ppkt.payload_length == 100, "Failed parsed pkt length check")
    air_assert(ppkt.payload_offset == 0, "Failed parsed pkt length check")
    air_assert(ppkt.header_length == 0, "Header length not 0 on init")

    # Replicate the packet
    repl = ppkt.replicate()
    air_assert(repl.payload_length == 100, "Failed repl pkt length check")
    air_assert(repl.payload_offset == 0, "Failed repl pkt length check")
    air_assert(repl.header_length == 0, "Repl header length not 0 on init")

    # Parse an ethernet header; verify packet updated, replicant not.
Example #7
0

if __name__ == "__main__":

    def transmit_handler(out_port, packet):
        logging.debug("Got call to send packet to %d" % out_port)

    logging.basicConfig(level=logging.DEBUG, filename=sys.argv[1])
    logging.info("RUNNING MODULE: %s" % __file__)

    from instance import IriInstance
    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"])