Esempio n. 1
0
 def start(self):
     self.cmd('ip', 'link', 'set', 'dev', 'lo', 'up')
     # for itf in self.intfList():
     #     for ip in itf.params.get(PRIVATE_IP_KEY, ()):
     #         self.cmd('ip', 'address', 'add', ip,
     #                  'dev', itf.name, 'scope', 'link')
     neighbor_to_intf = {otherIntf(itf).name: itf
                         for itf in self.intfList()}
     self.static_routes = [(p, v if v not in neighbor_to_intf
                            else neighbor_to_intf[v])
                           for p, v in self.static_routes]
     self.router.start()
Esempio n. 2
0
 def dump_cfg_info(self):
     cfg = cparser.ConfigParser()
     for key, val in self.config_params.iteritems():
         cfg.set(cparser.DEFAULTSECT, key, val)
     cfg.set(cparser.DEFAULTSECT,
             'json_hostname', 'unix://%s' % self.socket_path)
     cfg.set(cparser.DEFAULTSECT,
             'controller_instance_number',
             self.instance_number)
     connected_intfs = [itf
                        for itf in self.intfList()
                        if L3Router.is_l3router_intf(otherIntf(itf)) and
                        itf.name != 'lo']
     for itf in connected_intfs:
         cfg.add_section(itf.name)
         n = otherIntf(itf).node
         cfg.set(itf.name, 'hello_interval', n.hello_interval)
         cfg.set(itf.name, 'dead_interval', n.dead_interval)
     with open(self.cfg_path, 'w') as f:
         cfg.write(f)
     return (itf.name for itf in connected_intfs)
Esempio n. 3
0
 def _add_node(self, n, props):
     """Register a network node"""
     for itf in n.intfList():
         nh = otherIntf(itf)
         if not nh:
             continue  # Skip loopback and the likes
         props[nh.node.name] = {
             "ip": "%s/%s" % (itf.ip, itf.prefixLen),
             "name": itf.name,
             "bw": itf.params.get("bw", -1),
         }
     self.network[n.name] = props
Esempio n. 4
0
 def _add_node(self, n, props):
     """Register a network node"""
     for itf in n.intfList():
         nh = otherIntf(itf)
         if not nh:
             continue  # Skip loopback and the likes
         props[nh.node.name] = {
             'ip': '%s/%s' % (itf.ip, itf.prefixLen),
             'name': itf.name,
             'bw': itf.params.get('bw', -1)
         }
     self.network[n.name] = props
Esempio n. 5
0
 def start(self):
     self.cmd('ip', 'link', 'set', 'dev', 'lo', 'up')
     # for itf in self.intfList():
     #     for ip in itf.params.get(PRIVATE_IP_KEY, ()):
     #         self.cmd('ip', 'address', 'add', ip,
     #                  'dev', itf.name, 'scope', 'link')
     neighbor_to_intf = {
         otherIntf(itf).name: itf
         for itf in self.intfList()
     }
     self.static_routes = [
         (p, v if v not in neighbor_to_intf else neighbor_to_intf[v])
         for p, v in self.static_routes
     ]
     self.router.start()
Esempio n. 6
0
    def start(self):
        self.cmd('ip', 'link', 'set', 'dev', 'lo', 'up')
        for itf in self.intfList():
            # Set up the private ip
            ip = itf.params.get(PRIVATE_IP_KEY, ())
            self.cmd('ip', 'address', 'add', ip, 'dev', itf.name)
            # set up the secondary-ips
            if itf.params.get('secondary-ips'):
                for sec in itf.params.get('secondary-ips'):
                    self.cmd('ip', 'address', 'add', sec, 'dev', itf.name)

        neighbor_to_intf = {
            otherIntf(itf).name: itf
            for itf in self.intfList()
        }
        self.static_routes = [
            (p, v if v not in neighbor_to_intf else neighbor_to_intf[v])
            for p, v in self.static_routes
        ]

        if self.router:
            self.router.start()
Esempio n. 7
0
 def broadcast_domains(self):
     """Returns [ [ intf ]* ]"""
     domains = []
     itfs = (
         intf
         for n in self.values()
         for intf in n.intfList()
         if intf.name != "lo" and isBroadcastDomainBoundary(intf.node)
     )
     interfaces = {itf: False for itf in itfs}
     for intf, explored in interfaces.iteritems():
         # the interface already belongs to a broadcast domain
         if explored:
             continue
         # create a new domain
         bd = list()
         to_explore = [intf]
         while to_explore:
             # Explore one element
             i = to_explore.pop()
             if isBroadcastDomainBoundary(i.node):
                 bd.append(i)
                 if i in interfaces:
                     interfaces[i] = True
             # check its corresponding interface
             other = otherIntf(i)
             if isBroadcastDomainBoundary(other.node):
                 bd.append(other)
                 if other in interfaces:
                     interfaces[other] = True
             else:
                 # explode the node's interface to explore them
                 to_explore.extend([x for x in other.node.intfList() if x is not other and x.name != "lo"])
         domains.append(bd)
         for i in bd:
             i.params[BDOMAIN_KEY] = bd
     return domains
Esempio n. 8
0
    def broadcast_domains(self):
        """Returns [ [ intf ]* ]"""
        domains = []

        itfs = (intf for n in self.values() for intf in n.intfList()
                if intf.name != 'lo' and
                isBroadcastDomainBoundary(intf.node))
        interfaces = {itf: False for itf in itfs}
        for intf, explored in interfaces.iteritems():
            # the interface already belongs to a broadcast domain
            if explored:
                continue
            # create a new domain
            bd = list()
            to_explore = [intf]
            while to_explore:
                # Explore one element
                i = to_explore.pop()
                if isBroadcastDomainBoundary(i.node):
                    bd.append(i)
                    if i in interfaces:
                        interfaces[i] = True
                # check its corresponding interface
                other = otherIntf(i)
                if isBroadcastDomainBoundary(other.node):
                    bd.append(other)
                    if other in interfaces:
                        interfaces[other] = True
                else:
                    # explode the node's interface to explore them
                    to_explore.extend([x for x in other.node.intfList()
                                       if x is not other and x.name != 'lo'])
            domains.append(bd)
            for i in bd:
                i.params[BDOMAIN_KEY] = bd
        return domains
Esempio n. 9
0
 def add_node(self, n, props):
     for itf in n.intfList():
         props[otherIntf(itf).node.name] = {"ip": "%s/%s" % (itf.ip, itf.prefixLen), "name": itf.name}
     self.network[n.name] = props