def runOS(cmd, debug=DBG): """ run a os.system(cmd) """ LOG.debug(cmd) if not debug: os.system(cmd)
def run_process(cmd, debug=DBG): """ run the cmd """ LOG.debug(cmd) if not debug: p = Popen(cmd, shell=True, stdout=PIPE) p.wait() return p.stdout.read()
def commit_change(self): """ @API commit the changes, and applied the requirements entered for the current session """ for prefix in self.change_pfx: tmp = [] if not self.simple_req[prefix]: self.remove_dag_requirement(prefix) else: for item in self.simple_req[prefix]: for s, d in zip(item.path[:-1], item.path[1:]): if (s, d) not in tmp: tmp.append((s, d)) LOG.debug('add_dag_requirement') self.add_dag_requirement(prefix, IGPGraph(tmp)) del self.change_pfx[:] self.refresh_augmented_topo()
def Simplify(self, Req): """ @API Compute the minimum LabelsStack corresponding to :Req, based on view of the network """ LOG.debug('Simplifying %s' % str(Req)) Current_req = self.RewriteReq(Req) Finalsrc = Req[0] Finaldst = Req[-1] src = Finalsrc dst = Finaldst LabelsStack = list() finish = True while (finish): node = self.find_segment(Current_req, src, dst) if (node != False): if (node[0] != Finaldst or node[1] == 'adjacency'): attribute = node[1] newDest = node[0] dico = {'type': attribute} if (attribute == 'adjacency'): dico['prev'] = src LabelsStack.append((newDest, dico)) src = node[0] dst = Finaldst src_index = Req.index(src) dst_index = Req.index(dst) Current_req = Req[src_index:dst_index + 1] Current_req = self.RewriteReq(Current_req) else: finish = False if node[0] == Finaldst: finish = False else: Current_req.pop() dst = Current_req[-1][-1] LOG.debug('output: %s' % str(LabelsStack)) return LabelsStack
def Simplifier(self, Req): LOG.debug('Simplifying %s' % str(Req)) Current_req = self.RewriteReq(Req) Finalsrc = Req[0] Finaldst = Req[-1] src = Finalsrc dst = Finaldst srcIndex = 0 destIndex = len(Req) - 1 LabelsStack = list() finish = True while (finish): node = self.start_function(Current_req, src, dst) print 'output: %s ' % str(node) if (node != False): if (node[0] != Finaldst or node[1] == 'adjacency'): attribute = node[1] newDest = node[0] dico = {'type': attribute} if (attribute == 'adjacency'): dico['prev'] = src LabelsStack.append((newDest, dico)) src = node[0] dst = Finaldst src_index = Req.index(src) dst_index = Req.index(dst) Current_req = Req[src_index:dst_index + 1] Current_req = self.RewriteReq(Current_req) else: finish = False if node[0] == Finaldst: finish = False else: Current_req.pop() dst = Current_req[-1][-1] LOG.debug('output: %s' % str(LabelsStack)) return LabelsStack
def build(self): destinations = map(lambda x: x.get('name'), self.config.get('destinations')) controller = self.config.get('controller') for router in self.config.get('routers'): loaddr = socket.inet_ntop( socket.AF_INET6, socket.inet_pton(socket.AF_INET6, router.get('loopback-addr').split('/')[0]) ) + '/' + router.get('loopback-addr').split('/')[1] params = router.get('ospf6') if params.get('enable'): if router.get('name') == controller: self.add_controller(router.get('name'), loaddr, **params) else: self.add_router(router.get('name'), loaddr, **params) else: self.add_host(router.get('name')) n = self.get_node(router.get('name')) n.addr = loaddr ospf_link = {} for link in self.config.get('ospf-links'): ospf_link[link.get('name')] = link for link in self.config.get('link'): src = link.get('src') dest = link.get('dest') r1 = self.get_node(src.get('name')) r2 = self.get_node(dest.get('name')) srcAddr = socket.inet_ntop(socket.AF_INET6,\ socket.inet_pton(socket.AF_INET6, src.get('ip').split('/')[0] ))+'/'+src.get('ip').split('/')[1] destAddr = socket.inet_ntop(socket.AF_INET6,\ socket.inet_pton(socket.AF_INET6, dest.get('ip').split('/')[0]))+'/'+dest.get('ip').split('/')[1] if link.get('name') in ospf_link: o_l = ospf_link[link.get('name')] src_cost = link.get('cost') dest_cost = link.get('cost') if not link.get('bidirectional'): src_cost = link.get('src').get('cost') dest_cost = link.get('dest').get('cost') params1 = { 'area': o_l.get('src').get('ospf').get('area'), 'hello-interval': o_l.get('src').get('ospf').get('hello-interval'), 'dead-interval': o_l.get('src').get('ospf').get('dead-interval'), 'cost': src_cost } params2 = params1 = { 'area': o_l.get('dest').get('ospf').get('area'), 'hello-interval': o_l.get('dest').get('ospf').get('hello-interval'), 'dead-interval': o_l.get('dest').get('ospf').get('dead-interval'), 'cost': dest_cost } if not link.get('bidirectional'): self.add_ospf_link(r1, r2, srcAddr, destAddr, cost=link.get('cost'), delay=link.get('delay'), bw=link.get('bw'), directed=True, cost1=int(src_cost), cost2=int(dest_cost), params1=params1, params2=params2) else: self.add_ospf_link(r1, r2, srcAddr, destAddr, cost=link.get('cost'), delay=link.get('delay'), bw=link.get('bw'), params1=params1, params2=params2) else: self.add_link(r1, r2, srcAddr, destAddr, cost=link.get('cost'), delay=link.get('delay'), bw=link.get('bw')) LOG.debug('Adding link %s <-> %s', src.get('name'), dest.get('name')) if link.get('name') not in ospf_link: # destinations links : if src.get('name') in destinations and isinstance(r1, Host): r1.set_opposite_intf(destAddr) elif dest.get('name') in destinations and isinstance(r2, Host): r2.set_opposite_intf(srcAddr)