def start(self): self.logger.debug("Start ExaBGP Interface") self.server.start() start_time = time.clock() self.run = True while self.run: # get BGP messages from ExaBGP via stdin try: route = self.server.receiver_queue.get(True, 1) if route == "DONE": print str(time.clock() - start_time ) + ' finished with initial RIB construction' else: self.logger.debug("Received Route") route = json.loads(route) # process route advertisements - add/remove routes to/from rib of respective participant (neighbor) if 'neighbor' in route: if 'ip' in route['neighbor']: in_participant = self.config.portip_2_participant[ route['neighbor']['ip']] updates = self.rib.update(in_participant, route) # update local ribs - select best route for each prefix for update in updates: affected_participants = self.config.participants[ in_participant].peers_in decision_process(self.rib, affected_participants, self.config.participants, update) event = XCTRLEvent("RouteServer", "RIB UPDATE", updates) self.event_queue.put(event) elif 'notification' in route: for participant in self.config.participants: self.rib.process_notification(participant, route) except Queue.Empty: # self.logger.debug("Empty Queue") pass
def start(self): print "Start Server" self.xrs.server.start() while self.run: # get BGP messages from ExaBGP via stdin try: route = self.xrs.server.receiver_queue.get(True, 1) route = json.loads(route) # process route advertisements - add/remove routes to/from rib of respective participant (neighbor) updates = None if ('neighbor' in route): if ('ip' in route['neighbor']): updates = self.xrs.participants[ self.xrs.portip_2_participant[ route['neighbor']['ip']]].update(route) elif ('notification' in route): for participant in self.xrs.participants: self.xrs.participants[ participant].process_notification(route) if updates is not None: # update local ribs - select best route for each prefix for update in updates: decision_process(self.xrs.participants, update) # assign VNHs vnh_assignment(updates, self.xrs) # update supersets sdx_msgs = update_supersets(updates, self.xrs) # send supersets to SDX controller update_sdx_controller(sdx_msgs, self.xrs.rest_api_url) # BGP updates changes = bgp_update_peers(updates, self.xrs) # Send Gratuitous ARPs if changes: for change in changes: self.sdx_ap.send_gratuitous_arp(change) except Queue.Empty: if LOG: print "Empty Queue"
def start(self): print "Start Server" self.xrs.server.start() while self.run: # get BGP messages from ExaBGP via stdin try: route = self.xrs.server.receiver_queue.get(True, 1) route = json.loads(route) # process route advertisements - add/remove routes to/from rib of respective participant (neighbor) updates = None if ('neighbor' in route): if ('ip' in route['neighbor']): updates = self.xrs.participants[self.xrs.portip_2_participant[route['neighbor']['ip']]].update(route) elif ('notification' in route): for participant in self.xrs.participants: self.xrs.participants[participant].process_notification(route) if updates is not None: # update local ribs - select best route for each prefix for update in updates: decision_process(self.xrs.participants,update) # assign VNHs vnh_assignment(updates, self.xrs) # update supersets sdx_msgs = update_supersets(updates, self.xrs) # send supersets to SDX controller update_sdx_controller(sdx_msgs, self.xrs.rest_api_url) # BGP updates changes = bgp_update_peers(updates, self.xrs) # Send Gratuitous ARPs if changes: for change in changes: self.sdx_ap.send_gratuitous_arp(change) except Queue.Empty: if LOG: print "Empty Queue"
def start(self): self.server.start() while True: route = self.server.receiver_queue.get() route = json.loads(route) # TODO: check the RIB update flow with others ... # At the moment, I am updating the RIB and will attach next-hop to the announcement at the end updates = [] route_list = None # Update RIBs for participant_name in self.sdx.participants: route_list = self.sdx.participants[ participant_name].rs_client.update(route) if route_list: break # Best Path Selection algorithm for route_item in route_list: updates.extend( decision_process(self.sdx.participants, route_item)) # Check for withdraw routes for route in route_list: if (route is None): continue elif 'withdraw' in route: for VNH in self.sdx.VNH_2_pfx: if (route['withdraw']['prefix'] in list(self.sdx.VNH_2_pfx[VNH])): self.server.sender_queue.put( withdraw_route(route['withdraw'], self.sdx.VNH_2_IP[VNH])) break # Trigger policy updates bgp_trigger_update(self.event_queue, self.ready_queue) # Check for announced routes #if (route_list): # TODO: need to correct this glue logic if hasattr(self.sdx, 'VNH_2_pfx'): for VNH in self.sdx.VNH_2_pfx: for prefix in list(self.sdx.VNH_2_pfx[VNH]): for paticipant_name in self.sdx.participants: route = self.sdx.participants[ paticipant_name].rs_client.get_route( 'local', prefix) if route: self.server.sender_queue.put( announce_route(route, self.sdx.VNH_2_IP[VNH])) break
def start(self): self.server.start() while True: route = self.server.receiver_queue.get() route = json.loads(route) # TODO: check the RIB update flow with others ... # At the moment, I am updating the RIB and will attach next-hop to the announcement at the end updates = [] route_list = None # Update RIBs for participant_name in self.sdx.participants: route_list = self.sdx.participants[participant_name].rs_client.update(route) if route_list: break # Best Path Selection algorithm for route_item in route_list: updates.extend(decision_process(self.sdx.participants,route_item)) # Check for withdraw routes for route in route_list: if (route is None): continue elif 'withdraw' in route: for VNH in self.sdx.VNH_2_pfx: if(route['withdraw']['prefix'] in list(self.sdx.VNH_2_pfx[VNH])): self.server.sender_queue.put(withdraw_route(route['withdraw'],self.sdx.VNH_2_IP[VNH])) break # Trigger policy updates bgp_trigger_update(self.event_queue,self.ready_queue) # Check for announced routes #if (route_list): # TODO: need to correct this glue logic if hasattr(self.sdx, 'VNH_2_pfx'): for VNH in self.sdx.VNH_2_pfx: for prefix in list(self.sdx.VNH_2_pfx[VNH]): for paticipant_name in self.sdx.participants: route = self.sdx.participants[paticipant_name].rs_client.get_route('local',prefix) if route: self.server.sender_queue.put(announce_route(route,self.sdx.VNH_2_IP[VNH])) break
def update(self,route): origin = None as_path = None med = None atomic_aggregate = None if ('neighbor' in route): if ('ip' in route['neighbor']): # Only add to the RIB if it's from a participant who other than myself. if (route['neighbor']['ip'] not in self.ips): if ('update' in route['neighbor']): if ('attribute' in route['neighbor']['update']): attribute = route['neighbor']['update']['attribute'] origin = attribute['origin'] as_path = attribute['as-path'] med = attribute['med'] atomic_aggregate = attribute['atomic-aggregate'] if ('announce' in route['neighbor']['update']): announce = route['neighbor']['update']['announce'] if ('ipv4 unicast' in announce): for prefix in announce['ipv4 unicast'].keys(): self.rib["input"][prefix] = (announce['ipv4 unicast'][prefix]['next-hop'], origin, ' '.join(map(str,as_path)).replace('[','').replace(']',''), med, atomic_aggregate) self.rib["input"].commit() best_route = decision_process(self.rib["input"],prefix) if (best_route is not None): self.rib["local"].delete(prefix) self.rib["local"][prefix] = best_route self.rib["local"].commit() #queue.put(self.announce_route(best_route)) return {'announce':best_route} elif ('withdraw' in route['neighbor']['update']): withdraw = route['neighbor']['update']['withdraw'] if ('ipv4 unicast' in withdraw): for prefix in withdraw['ipv4 unicast'].keys(): deleted_route = self.rib["input"][prefix] self.rib["input"].delete(prefix) self.rib["input"].commit() self.rib["local"].delete(prefix) self.rib["local"].commit() #queue.put(self.withdraw_route(deleted_route)) # TODO: clarify how the route withdrawal will work i.e., do we have to run the decision process again return {'withdraw':deleted_route} elif ('notification' in route): return if ('shutdown' == route['notification']): self.rib["input"].delete_all() self.rib["input"].commit() self.rib["local"].delete_all() self.rib["local"].commit() # TODO: send shutdown notification to participants return