diff --git a/flowspec/models.py b/flowspec/models.py index 537ad9b136f05965c9aded882c2c5d6e0ab08fe6..9181bd98cca090db49e633ae1534002b84b7d92b 100644 --- a/flowspec/models.py +++ b/flowspec/models.py @@ -226,13 +226,13 @@ class Route(models.Model): logger.error("model::route::ip_version(): exception in trying to determine ip_version: "+str(e)) pass - logger.debug("model::route::ip_version(): source_ip_version="+str(source_ip_version)+" destination_ip_version="+str(destination_ip_version)) + #logger.debug("model::route::ip_version(): source_ip_version="+str(source_ip_version)+" destination_ip_version="+str(destination_ip_version)) if source_ip_version != destination_ip_version: logger.error("model::route::ip_version(): source_ip_version="+str(source_ip_version)+" != destination_ip_version="+str(destination_ip_version)) return -1 ip_version = source_ip_version and destination_ip_version - logger.debug("model::route::ip_version(): ip_version="+str(ip_version)) + #logger.debug("model::route::ip_version(): ip_version="+str(ip_version)) return ip_version @@ -503,17 +503,17 @@ class Route(models.Model): #logger.debug('models::is_synced(): loop flow='+str(flow)+' route='+str(route)) if route.name == self.name: found = True - logger.debug('models::is_synced(): Found a matching rule name') + logger.debug('models::is_synced(): found a matching rule name for self='+str(self)) devicematch = route.match try: assert(self.destination) assert(devicematch['destination'][0]) if self.destination == devicematch['destination'][0]: found = found and True - logger.debug('models::is_synced(): Found a matching destination') + logger.debug('models::is_synced(): self='+str(self)+': found a matching destination') else: found = False - logger.debug('models::is_synced(): Destination fields do not match') + logger.info('models::is_synced(): self='+str(self)+': destination fields do not match') except: pass try: @@ -521,10 +521,10 @@ class Route(models.Model): assert(devicematch['source'][0]) if self.source == devicematch['source'][0]: found = found and True - logger.debug('models::is_synced(): Found a matching source') + logger.debug('models::is_synced(): self='+str(self)+': found a matching source') else: found = False - logger.debug('models::is_synced(): Source fields do not match') + logger.info('models::is_synced(): self='+str(self)+': source fields do not match') except: pass @@ -536,10 +536,10 @@ class Route(models.Model): intersect = list(set(devitems).intersection(set(dbitems))) if ((len(intersect) == len(dbitems)) and (len(intersect) == len(devitems))): found = found and True - logger.debug('models::is_synced(): Found a matching fragment type') + logger.debug('models::is_synced(): self='+str(self)+': found a matching fragment type') else: found = False - logger.debug('models::is_synced(): Fragment type fields do not match') + logger.info('models::is_synced(): self='+str(self)+': fragment type fields do not match') except: pass @@ -551,10 +551,10 @@ class Route(models.Model): intersect = list(set(devitems).intersection(set(dbitems))) if ((len(intersect) == len(dbitems)) and (len(intersect) == len(devitems))): found = found and True - logger.debug('models::is_synced(): Found a matching port type') + logger.debug('models::is_synced(): self='+str(self)+': found a matching port type') else: found = False - logger.debug('models::is_synced(): Port type fields do not match') + logger.info('models::is_synced(): self='+str(self)+': port type fields do not match') except: pass @@ -564,15 +564,15 @@ class Route(models.Model): devitems = devicematch['protocol'] #dbitems = ["%s"%i for i in self.protocol.all()] dbitems = [map__ip_proto__for__ip_version__to_flowspec(my_ip_version, "%s"%i) for i in self.protocol.all()] - logger.info("models::is_synced(): dbitems="+str(dbitems)) + #logger.info("models::is_synced(): dbitems="+str(dbitems)) intersect = list(set(devitems).intersection(set(dbitems))) if ((len(intersect) == len(dbitems)) and (len(intersect) == len(devitems))): found = found and True - logger.debug('models::is_synced(): Found a matching protocol type') + logger.debug('models::is_synced(): self='+str(self)+': found a matching protocol type') else: found = False - logger.debug('Protocol type fields do not match') + logger.info('models::is_synced(): self='+str(self)+': protocol type fields do not match') except: pass @@ -584,10 +584,10 @@ class Route(models.Model): intersect = list(set(devitems).intersection(set(dbitems))) if ((len(intersect) == len(dbitems)) and (len(intersect) == len(devitems))): found = found and True - logger.debug('models::is_synced(): Found a matching destination port type') + logger.debug('models::is_synced(): self='+str(self)+': found a matching destination port type') else: found = False - logger.debug('models::is_synced(): Destination port type fields do not match') + logger.info('models::is_synced(): self='+str(self)+': destination port type fields do not match') except: pass @@ -599,10 +599,10 @@ class Route(models.Model): intersect = list(set(devitems).intersection(set(dbitems))) if ((len(intersect) == len(dbitems)) and (len(intersect) == len(devitems))): found = found and True - logger.debug('models::is_synced(): Found a matching source port type') + logger.debug('models::is_synced(): self='+str(self)+': found a matching source port type') else: found = False - logger.debug('models::is_synced(): Source port type fields do not match') + logger.info('models::is_synced(): self='+str(self)+': source port type fields do not match') except: pass @@ -612,10 +612,10 @@ class Route(models.Model): # assert(devicematch['fragment'][0]) # if self.fragmenttype == devicematch['fragment'][0]: # found = found and True -# logger.debug('Found a matching fragment type') +# logger.debug('self='+str(self)+': found a matching fragment type') # else: # found = False -# logger.debug('Fragment type fields do not match') +# logger.info('models::is_synced(): self='+str(self)+': fragment type fields do not match') # except: # pass try: @@ -623,10 +623,10 @@ class Route(models.Model): assert(devicematch['icmp-code'][0]) if self.icmpcode == devicematch['icmp-code'][0]: found = found and True - logger.debug('models::is_synced(): Found a matching icmp code') + logger.debug('models::is_synced(): self='+str(self)+': found a matching icmp code') else: found = False - logger.debug('models::is_synced(): Icmp code fields do not match') + logger.info('models::is_synced(): self='+str(self)+': icmp code fields do not match') except: pass try: @@ -634,20 +634,22 @@ class Route(models.Model): assert(devicematch['icmp-type'][0]) if self.icmptype == devicematch['icmp-type'][0]: found = found and True - logger.debug('models::is_synced(): Found a matching icmp type') + logger.debug('models::is_synced(): self='+str(self)+': found a matching icmp type') else: found = False - logger.debug('models::is_synced(): Icmp type fields do not match') + logger.info('models::is_synced(): self='+str(self)+': icmp type fields do not match') except: pass if found and self.status != "ACTIVE": - logger.error('models::is_synced(): Rule '+str(route)+' is applied on device but appears in DB as offline') + logger.error('models::is_synced(): rule '+str(self)+' is applied on device but appears in DB as offline') #self.status = "ACTIVE" #self.save() self.update_status("ACTIVE") found = True if self.status == "ADMININACTIVE" or self.status == "INACTIVE" or self.status == "INACTIVE_TODELETE" or self.status == "PENDING_TODELETE" or self.status == "EXPIRED": found = True + + logger.info('models::is_synced(): self='+str(self)+ " => returning found="+str(found)) return found def get_then(self): diff --git a/utils/proxy.py b/utils/proxy.py index 0e2620d1b16737feac4eabe006f7801452c226cc..9fb64f35d95a515f75b8839901c32697c2114806 100644 --- a/utils/proxy.py +++ b/utils/proxy.py @@ -64,6 +64,7 @@ class Retriever(object): xmlconfig = self.xml else: xmlconfig = self.fetch_xml() + #logger.info("Retriever::get_xml(): xmlconfig="+str(xmlconfig)) return xmlconfig def proccess_xml(self): @@ -71,6 +72,9 @@ class Retriever(object): parser = np.Parser() parser.confile = xmlconfig device = parser.export() + #logger.info("Retriever::proccess_xml(): => device="+str(device)) + #logger.info("Retriever::proccess_xml(): device.routing_options="+str(device.routing_options)) + #logger.info("Retriever::proccess_xml(): device.routing_options->routes="+str([flow.routes for flow in device.routing_options])) return device def proccess_xml_generic(self): @@ -80,14 +84,14 @@ class Retriever(object): def fetch_device(self): device = cache.get("device") - logger.info("[CACHE] hit! got device") + logger.info("Retriever::fetch_device(): [CACHE] hit! got cached device") if device: return device else: device = self.proccess_xml() if device.routing_options: cache.set("device", device, 3600) - logger.info("[CACHE] miss, setting device") + logger.info("Retriever::fetch_device(): [CACHE] miss, setting device") return device else: return False @@ -121,7 +125,7 @@ class Applier(object): route.match['destination-v6'].append(route_obj.destination) def to_xml(self, operation=None): - logger.info("Operation: %s"%operation) + logger.info("proxy::Applier::to_xml(): Operation: %s"%operation) if self.route_object: @@ -129,13 +133,13 @@ class Applier(object): settings.PORTRANGE_LIMIT except: settings.PORTRANGE_LIMIT = 100 - logger.info("Generating XML config") + logger.info("proxy::Applier::to_xml:(): Generating XML config") route_obj = self.route_object ip_version = self.route_object.ip_version() is_ipv4 = self.route_object.is_ipv4() - logger.info("proxy::to_xml(): is_ipv4="+str(is_ipv4)) + logger.info("proxy::Applier::to_xml(): is_ipv4="+str(is_ipv4)) device = np.Device() flow = np.Flow(is_ipv4) @@ -145,7 +149,7 @@ class Applier(object): route.name = route_obj.name if operation == "delete": - logger.info("Requesting a delete operation") + logger.info("proxy::Applier::to_xml(): Requesting a delete operation") route.operation = operation device = device.export(netconf_config=True) return ET.tostring(device) @@ -208,7 +212,7 @@ class Applier(object): else: route.then[thenaction.action] = True if operation == "replace": - logger.info("Requesting a replace operation") + logger.info("proxy::Applier::to_xml(): Requesting a replace operation") route.operation = operation device = device.export(netconf_config=True) result = ET.tostring(device)