コード例 #1
0
ファイル: router.py プロジェクト: visemet/netman
    def initialize(self):
        """
        Initializes the router.
        """

        events = []

        # Creates a flow for each neighbor of the router
        for dest in self.neighbors():
            if not isinstance(dest, Router):
                continue

            congestion = AIMD()

            flow = Flow(congestion)
            flow.start(0)
            flow.dest(dest)

            congestion.initialize(flow)

            self._flows[dest] = flow
            self._changed[dest] = False

        # Initializes the routing algorithm
        self._algorithm.initialize(self)

        for (dest, flow) in self._flows.iteritems():
            packet = self._create_packet(self, dest)

            packet.set_create_time(flow.start())

            port = self._algorithm.next(dest)

            # Checks that destination is reachable
            if port is None:
                continue

            # Creates an event for the starting time of the flow
            create_event = self._create_event(flow.start(), port, Event._CREATE, packet)
            events.append(create_event)

        self._next_update += Router._UPDATE_EVERY

        return events
コード例 #2
0
ファイル: setup.py プロジェクト: visemet/netman
    def _initialize(self, config):
        curr_type = -1
        devices = {}
        links = {}
        flows = {}
        measure_flows = {}
        measure_links = {}

        for line in config:
            line = line.strip()

            if line in self._type_format:
                curr_type = self._type_format[line]
                continue
 
            # Hosts
            if curr_type == 0:
                [name] = line.split(', ')
                host = Host(name)
                devices[name] = host

            # Routers
            elif curr_type == 1:
                [name, algorithm] = line.split(', ')

                if algorithm == BellmanFord._TYPE:
                    algorithm = BellmanFord()

                router = Router(algorithm, name)
                devices[name] = router

            # Connections
            elif curr_type == 2:
                [name, source, dest, rate, delay, size] = line.split(', ')

                source_device = devices[source]
                dest_device = devices[dest]
                rate = int(rate)
                delay = float(delay)
                size = int(size)

                source_link = Link()
                dest_link = Link()

                source_port = Port()
                source_port.source(source_device)
                source_port.conn(dest_link)
                source_port.incoming(Buffer(size))
                source_port.outgoing(Buffer(size))

                dest_port = Port()
                dest_port.source(dest_device)
                dest_port.conn(source_link)
                dest_port.incoming(Buffer(size))
                dest_port.outgoing(Buffer(size))

                source_link.dest(source_port)
                source_link.rate(rate)
                source_link.delay(delay)
                source_link.getTracker().set_delay(delay)

                dest_link.dest(dest_port)
                dest_link.rate(rate)
                dest_link.delay(delay)
                dest_link.getTracker().set_delay(delay)

                source_device.enable(source_port)
                dest_device.enable(dest_port)
                
                links[name] = dest_link

            # Flows
            elif curr_type == 3:
                [name, source, dest, size, time, algorithm] = line.split(', ')

                source_device = devices[source]
                dest_device = devices[dest]
                size = int(size)
                time = float(time)

                if algorithm == AIMD._TYPE:
                    algorithm = AIMD()
                elif algorithm == FAST._TYPE:
                    algorithm = FAST()

                flow = Flow(algorithm)
                flow.bits(size)
                flow.start(time)
                flow.dest(dest_device)

                algorithm.initialize(flow)

                source_device.connect(flow)
                
                flows[name] = flow

            # Measurables
            elif curr_type == 4:
                # TODO: track measurables
                [name, type] = line.split(', ')
                if type == "flow":
                    measure_flows[name] = flows[name]
                elif type == "link":
                    measure_links[name] = links[name]

        return (devices.values(), measure_flows, measure_links)