Example #1
0
def test_dv():
    hns_addr = config.Address('127.0.0.1', 8888)
    self_addr = config.Address('127.0.0.1', 8890)
    c = config.Config(config.Algorithm.DV, 'B', self_addr, hns_addr, 30, 5)
    r = router.Router(c)
    r.run()

    import time
    time.sleep(3)
    r.update_neighbor('A', 2)
    r.update_neighbor('D', 3)
Example #2
0
def test_centralized():
    hns_addr = config.Address('127.0.0.1', 8888)
    self_addr = config.Address('127.0.0.1', 8889)
    c = config.Config(config.Algorithm.LS_CENTRALIZE, 'A', self_addr, hns_addr,
                      30, 5, 'E')
    r = router.Router(c)
    r.run()

    import time
    time.sleep(3)
    r.update_neighbor('E', 1)
    r.update_neighbor('B', 2)
    r.update_neighbor('C', 1)
    r.update_neighbor('D', 4)
 def _validate_init(self, _config):
     try:
         hns_addr = config.Address(_config['hns_ip'], _config['hns_port'])
         self_addr = config.Address(_config['ip'], _config['port'])
         print(alg[_config['algorithm']])
         c = config.Config(
             algorithm=alg[_config['algorithm']],
             hostname=_config['hostname'],
             self_addr=self_addr,
             hns_addr=hns_addr,
             dead_timeout=_config['dead_timeout'],
             update_interval=_config['update_interval'],
             controller_hostname=_config['controller_hostname'])
         _router = router.Router(c)
         for each in _config['neighbors']:
             _router.update_neighbor(each['hostname'], each['cost'])
         manager.init_router(_router)
     except Exception as err:
         raise err
Example #4
0
def test_centralized():
    hns_addr = config.Address('127.0.0.1', 8888)
    self_addr = config.Address('127.0.0.1', 8890)
    c = config.Config(config.Algorithm.LS_CENTRALIZE, 'B', self_addr, hns_addr,
                      30, 5, 'E')
    r = router.Router(c)
    r.run()

    import time
    time.sleep(3)
    r.update_neighbor('E', 1)
    r.update_neighbor('A', 2)
    r.update_neighbor('D', 3)
    r.update_neighbor('C', 2)

    time.sleep(20)
    r.stop()
    print('{} b stop'.format(time.ctime()))

    time.sleep(60)
    r.run()
    print('{} b restart'.format(time.ctime()))