Пример #1
0
    def turn_on_router(self, router: Router):
        router.start()  # Run the process

        new_router_meta = router.meta

        message = AddRouterMessage(new_router_meta)
        for current_router_meta in self.routers_info.values():
            self.queues_list[current_router_meta.id].put(message)

        self.routers_info[new_router_meta.id] = new_router_meta
Пример #2
0
def test_router():
    router1 = Router("192.168.0.1")
    router2 = Router("192.168.0.2")
    router3 = Router("192.168.0.3")
    router1.link(router2)
    router1.add_forwarding_table_entry(router3, router2)
    assert (router1.connected_devices == [router2])
    assert (router1.forwarding_table[router2] == router2)
    assert (router1.forwarding_table[router3] == router2)
Пример #3
0
 def redteam_blueteam_create(self, data, requirements):
     """Create the heat infrastructure"""
     for device_name in data['resources']:
         if data['resources'][device_name]['type'] == 'router':
             for team_name, team_data in self.get_teams(data):
                 router = Router(data['resources'], self.template,
                                 team_name, device_name,
                                 self.allocated_subnets)
                 self.router_list.append(router)
                 self.allocated_subnets = router.get_allocated_subnets()
     for device_name in data['resources']:
         if data['resources'][device_name]['type'] == 'node':
             service_file_created = False
             for team_name, team_data in self.get_teams(data):
                 node = Node(data['resources'], team_name, self.template,
                             device_name, service_file_created,
                             requirements)
                 self.metadata['nodes'].append(
                     str(team_name + '_' + device_name))
Пример #4
0
    def add_router(self, x, y):
        free_id = self._find_free_id()
        if free_id == -1:
            print('There are no place for new routers, max count:',
                  self.MAX_ROUTERS_COUNT)
            return

        self._curr_id = free_id
        self.id_free_list[self._curr_id] = False

        # add edge
        for router_id, router in self.routers.items():
            if router.meta.range(x, y) <= self.ROUTERS_RANGE:
                self.edge_list.append([router_id, self._curr_id])

        new_router = Router(x, y, self.ROUTERS_RANGE, self._curr_id,
                            self.queue_list, self.routerStates)
        self.routers[self._curr_id] = new_router

        self._server.turn_on_router(new_router)
Пример #5
0
def main():
    prompt = [
        "N for new router", "A for a new interface",
        "D for done with current router", "Q to finish", "R for a reminder"
    ]
    inp = input(prompt)
    while inp != "Q":
        if (inp == "N"):
            router = Router()
            print("You created a router called %s" % router.hostname)
        if (inp == "A"):
            router.add_interface()
            print("You created an interface")
        if (inp == "D"):
            print(
                "Check this directory for a text file with this hostname you provided"
            )
            router.done()
        if (inp == "R"):
            print(prompt)
        inp = input("R for a reminder of commands | Enter command: ")
Пример #6
0
def test_router():
    router1 = Router("192.168.0.1")
    router2 = Router("192.168.0.2")
    router3 = Router("192.168.0.3")
    router1.link(router2)
    router1.add_forwarding_table_entry(router3, router2)
    assert (router1.device_type() == Device_Type.ROUTER)
    assert (router2.device_type() == Device_Type.ROUTER)
    assert (router3.device_type() == Device_Type.ROUTER)
    assert (router1.connected_devices == {router2})
    assert (router1.forwarding_table[router2] == router2)
    assert (router1.forwarding_table[router3] == router2)
Пример #7
0
from src.router import Router

if __name__ == "__main__":
    rout = Router()
    rout.start_up()
Пример #8
0
 def add_router(self, ip: str, buffer_cap=5):
     self.routers[ip] = Router(ip, buffer_cap)
     self.devices[ip] = self.routers[ip]
Пример #9
0
 def test_router_get_route(self):
     router = Router()
     router.add_route(route_1)
     self.assertEqual(router.get_route('/'), route_1.func)
Пример #10
0
    def test_router_set_route(self):
        router = Router()

        router.add_route(route_1)
        self.assertEqual(router.routes[0], route_1)
Пример #11
0
    def test_create_router_with_routes(self):

        router = Router(routes=routes)
        self.assertEqual(router.routes, routes)
Пример #12
0
 def test_create_router(self):
     router = Router()
     self.assertEqual(router.routes, [])
Пример #13
0
def default_router():
    name = 'default'
    router = Router(name)
    return router
Пример #14
0
 def add_router(self, ip: str):
     self.routers[ip] = Router(ip)
     self.devices[ip] = self.routers[ip]
Пример #15
0
devices = {}

with open(users_path, "r") as rf:
	users = json.load(rf)

with open(devices_path, "r") as rf:
	devices = json.load(rf)

adress="192.168.1.4"
serv_port=50500
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((adress, serv_port))
sock.listen()

router = Router()

print("SERVER STARTED")
while(1):

	so, adr=sock.accept()
	#so.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY,1)	# send data separately
	print("-----\nNEW CONNECTION")
	print(adr)
	mac=so.recv(6)
	mac=binascii.hexlify(mac).decode()
	print(mac)
	
	username = ''
	device = ''