def handle_flow_in(self, event): if not event.active: return CONTINUE indatapath = netinet.create_datapathid_from_host(event.datapath_id) route = pyrouting.Route() sloc = event.route_source if sloc == None: sloc = event.src_location['sw']['dp'] route.id.src = netinet.create_datapathid_from_host(sloc) inport = event.src_location['port'] sloc = sloc | (inport << 48) else: route.id.src = netinet.create_datapathid_from_host(sloc & DP_MASK) inport = (sloc >> 48) & PORT_MASK if len(event.route_destinations) > 0: dstlist = event.route_destinations else: dstlist = event.dst_locations checked = False for dst in dstlist: if isinstance(dst, dict): if not dst['allowed']: continue dloc = dst['authed_location']['sw']['dp'] route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK) outport = dst['authed_location']['port'] dloc = dloc | (outport << 48) else: dloc = dst route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK) outport = (dloc >> 48) & PORT_MASK if dloc == 0: continue if self.routing.get_route(route): checked = True if self.routing.check_route(route, inport, outport): log.debug('Found route %s.' % hex(route.id.src.as_host())+\ ':'+str(inport)+' to '+hex(route.id.dst.as_host())+\ ':'+str(outport)) if route.id.src == route.id.dst: firstoutport = outport else: firstoutport = route.path[0].outport p = [] if route.id.src == route.id.dst: p.append(str(inport)) p.append(str(indatapath)) p.append(str(firstoutport)) else: s2s_links = len(route.path) p.append(str(inport)) p.append(str(indatapath)) for i in range(0,s2s_links): p.append(str(route.path[i].dst)) p.append(str(outport)) self.routing.setup_route(event.flow, route, inport, \ outport, FLOW_TIMEOUT, [], True) # Send Barriers pending_route = [] #log.debug("Sending BARRIER to switches:") # Add barrier xids for dpid in p[1:len(p)-1]: log.debug("Sending barrier to %s", dpid) pending_route.append(self.send_barrier(int(dpid,16))) # Add packetout info pending_route.append([indatapath, inport, event]) # Store new pending_route (waiting for barrier replies) self.pending_routes.append(pending_route) # send path to be highlighted to GUI self.send_to_gui("highlight",p) # Send packet out (do it after receiving barrier(s)) if indatapath == route.id.src or \ pyrouting.dp_on_route(indatapath, route): pass #self.routing.send_packet(indatapath, inport, \ # openflow.OFPP_TABLE,event.buffer_id,event.buf,"", \ # False, event.flow) else: log.debug("Packet not on route - dropping.") return CONTINUE else: log.debug("Invalid route between %s." \ % hex(route.id.src.as_host())+':'+str(inport)+' to '+\ hex(route.id.dst.as_host())+':'+str(outport)) else: log.debug("No route between %s and %s." % \ (hex(route.id.src.as_host()), hex(route.id.dst.as_host()))) if not checked: if event.flow.dl_dst.is_broadcast(): log.debug("Setting up FLOOD flow on %s", str(indatapath)) self.routing.setup_flow(event.flow, indatapath, \ openflow.OFPP_FLOOD, event.buffer_id, event.buf, \ BROADCAST_TIMEOUT, "", \ event.flow.dl_type == htons(ethernet.IP_TYPE)) else: inport = ntohs(event.flow.in_port) log.debug("Flooding") self.routing.send_packet(indatapath, inport, \ openflow.OFPP_FLOOD, \ event.buffer_id, event.buf, "", \ event.flow.dl_type == htons(ethernet.IP_TYPE),\ event.flow) else: log.debug("Dropping packet") return CONTINUE
def handle_flow_in(self, event): if not event.active: return CONTINUE indatapath = netinet.create_datapathid_from_host(event.datapath_id) route = pyrouting.Route() sloc = event.route_source if sloc == None: sloc = event.src_location['sw']['dp'] route.id.src = netinet.create_datapathid_from_host(sloc) inport = event.src_location['port'] sloc = sloc | (inport << 48) else: route.id.src = netinet.create_datapathid_from_host(sloc & DP_MASK) inport = (sloc >> 48) & PORT_MASK if len(event.route_destinations) > 0: dstlist = event.route_destinations else: dstlist = event.dst_locations checked = False for dst in dstlist: if isinstance(dst, dict): if not dst['allowed']: continue dloc = dst['authed_location']['sw']['dp'] route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK) outport = dst['authed_location']['port'] dloc = dloc | (outport << 48) else: dloc = dst route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK) outport = (dloc >> 48) & PORT_MASK if dloc == 0: continue if self.routing.get_route(route): checked = True if self.routing.check_route(route, inport, outport): log.err('Found route %s.' % hex(route.id.src.as_host()) + ':' + str(inport) + ' to ' + hex(route.id.dst.as_host()) + ':' + str(outport)) self.routing.setup_route(event.flow, route, inport, outport, FLOW_TIMEOUT, [], True) if indatapath == route.id.src or pyrouting.dp_on_route( indatapath, route): self.routing.send_packet(indatapath, inport, openflow.OFPP_TABLE, event.buffer_id, event.buf, "", False, event.flow) else: log.err("Packet not on route - dropping.") return CONTINUE else: log.err("Invalid route between %s." % hex(route.id.src.as_host()) + ':' + str(inport) + ' to ' + hex(route.id.dst.as_host()) + ':' + str(outport)) else: log.err( "No route between %s and %s." % (hex(route.id.src.as_host()), hex(route.id.dst.as_host()))) if not checked: log.err('Broadcasting packet') if event.flow.dl_dst.is_broadcast(): self.routing.setup_flow( event.flow, indatapath, openflow.OFPP_FLOOD, event.buffer_id, event.buf, BROADCAST_TIMEOUT, "", event.flow.dl_type == htons(ethernet.IP_TYPE)) else: inport = ntohs(event.flow.in_port) self.routing.send_packet( indatapath, inport, openflow.OFPP_FLOOD, event.buffer_id, event.buf, "", event.flow.dl_type == htons(ethernet.IP_TYPE), event.flow) else: log.err("Dropping packet") return CONTINUE
def handle_flow_in(self, event): if not event.active: return CONTINUE indatapath = netinet.create_datapathid_from_host(event.datapath_id) route = pyrouting.Route() sloc = event.route_source if sloc == None: sloc = event.src_location['sw']['dp'] route.id.src = netinet.create_datapathid_from_host(sloc) inport = event.src_location['port'] sloc = sloc | (inport << 48) else: route.id.src = netinet.create_datapathid_from_host(sloc & DP_MASK) inport = (sloc >> 48) & PORT_MASK if len(event.route_destinations) > 0: dstlist = event.route_destinations else: dstlist = event.dst_locations checked = False for dst in dstlist: if isinstance(dst, dict): if not dst['allowed']: continue dloc = dst['authed_location']['sw']['dp'] route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK) outport = dst['authed_location']['port'] dloc = dloc | (outport << 48) else: dloc = dst route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK) outport = (dloc >> 48) & PORT_MASK if dloc == 0: continue if self.routing.get_route(route): checked = True if self.routing.check_route(route, inport, outport): log.debug('Found route %s.' % hex(route.id.src.as_host())+\ ':'+str(inport)+' to '+hex(route.id.dst.as_host())+\ ':'+str(outport)) if route.id.src == route.id.dst: firstoutport = outport else: firstoutport = route.path[0].outport p = [] if route.id.src == route.id.dst: p.append(str(inport)) p.append(str(indatapath)) p.append(str(firstoutport)) else: s2s_links = len(route.path) p.append(str(inport)) p.append(str(indatapath)) for i in range(0, s2s_links): p.append(str(route.path[i].dst)) p.append(str(outport)) #print 'unicast' #print type(event.flow) #print dir(event.flow) #print str(event.flow)#.to_string() self.routing.setup_route(event.flow, route, inport, \ outport, FLOW_TIMEOUT, [], True) # Send Barriers pending_route = [] #log.debug("Sending BARRIER to switches:") # Add barrier xids for dpid in p[1:len(p) - 1]: log.debug("Sending barrier to %s", dpid) pending_route.append(self.send_barrier(int(dpid, 16))) # Add packetout info pending_route.append([indatapath, inport, event]) # Store new pending_route (waiting for barrier replies) self.pending_routes.append(pending_route) # send path to be highlighted to GUI #self.send_to_gui("highlight",p) # Send packet out (do it after receiving barrier(s)) if indatapath == route.id.src or \ pyrouting.dp_on_route(indatapath, route): #pass self.routing.send_packet(indatapath, inport, \ openflow.OFPP_TABLE,event.buffer_id,event.buf,"", \ False, event.flow) else: log.debug("Packet not on route - dropping.") return CONTINUE else: log.debug("Invalid route between %s." \ % hex(route.id.src.as_host())+':'+str(inport)+' to '+\ hex(route.id.dst.as_host())+':'+str(outport)) else: log.debug("No route between %s and %s." % \ (hex(route.id.src.as_host()), hex(route.id.dst.as_host()))) if not checked: #just broadcast to external port #black food eth = ethernet(event.buf) if eth.type != ethernet.IP_TYPE and\ eth.type != ethernet.ARP_TYPE and\ eth.type != ethernet.PAE_TYPE and\ eth.type != ethernet.VLAN_TYPE: return CONTINUE for d in self.dp_stats: for port in self.dp_stats[d]['ports']: if not self.pytop.is_internal(\ netinet.create_datapathid_from_host(d),port): self.send_openflow_packet(d, event.buf, port) return STOP if event.flow.dl_dst.is_broadcast(): log.debug("Setting up FLOOD flow on %s", str(indatapath)) self.routing.setup_flow(event.flow, indatapath, \ openflow.OFPP_FLOOD, event.buffer_id, event.buf, \ BROADCAST_TIMEOUT, "", \ event.flow.dl_type == htons(ethernet.IP_TYPE)) else: inport = ntohs(event.flow.in_port) log.debug("Flooding") #print 'flooding ' self.routing.send_packet(indatapath, inport, \ openflow.OFPP_FLOOD, \ event.buffer_id, event.buf, "", \ event.flow.dl_type == htons(ethernet.IP_TYPE),\ event.flow) else: log.debug("Dropping packet") return STOP
def handle_flow_in(self, event): if not event.active: return CONTINUE indatapath = netinet.create_datapathid_from_host(event.datapath_id) route = pyrouting.Route() sloc = event.route_source if sloc == None: sloc = event.src_location['sw']['dp'] route.id.src = netinet.create_datapathid_from_host(sloc) inport = event.src_location['port'] sloc = sloc | (inport << 48) else: route.id.src = netinet.create_datapathid_from_host(sloc & DP_MASK) inport = (sloc >> 48) & PORT_MASK if len(event.route_destinations) > 0: dstlist = event.route_destinations else: dstlist = event.dst_locations checked = False for dst in dstlist: if isinstance(dst, dict): if not dst['allowed']: continue dloc = dst['authed_location']['sw']['dp'] route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK) outport = dst['authed_location']['port'] dloc = dloc | (outport << 48) else: dloc = dst route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK) outport = (dloc >> 48) & PORT_MASK if dloc == 0: continue if self.routing.get_route(route): checked = True if self.routing.check_route(route, inport, outport): log.err('Found route %s.' % hex(route.id.src.as_host())+':'+str(inport)+' to '+hex(route.id.dst.as_host())+':'+str(outport)) self.routing.setup_route(event.flow, route, inport, outport, FLOW_TIMEOUT, [], True) if indatapath == route.id.src or pyrouting.dp_on_route(indatapath, route): self.routing.send_packet(indatapath, inport, openflow.OFPP_TABLE, event.buffer_id, event.buf, "", False, event.flow) else: log.err("Packet not on route - dropping.") return CONTINUE else: log.err("Invalid route between %s." % hex(route.id.src.as_host())+':'+str(inport)+' to '+hex(route.id.dst.as_host())+':'+str(outport)) else: log.err("No route between %s and %s." % (hex(route.id.src.as_host()), hex(route.id.dst.as_host()))) if not checked: log.err('Broadcasting packet') if event.flow.dl_dst.is_broadcast(): self.routing.setup_flow(event.flow, indatapath, openflow.OFPP_FLOOD, event.buffer_id, event.buf, BROADCAST_TIMEOUT, "", event.flow.dl_type == htons(ethernet.IP_TYPE)) else: inport = ntohs(event.flow.in_port) self.routing.send_packet(indatapath, inport, openflow.OFPP_FLOOD, event.buffer_id, event.buf, "", event.flow.dl_type == htons(ethernet.IP_TYPE), event.flow) else: log.err("Dropping packet") return CONTINUE