def handle_flow_stats_in(self, event): """ Extract 'action' from the matching flow entry in order to see find the next hop """ if c_ntohl(event.xid) == self.pending_query_xid: # See action(s) for this entry if len(event.flows) != 1: log.debug("matched to more than one flow entry! this should not happen") ports = [] for action in event.flows[0]['actions']: if action['type'] == 0: ports.append(action['port']) #elif ADD other action types here dpid = netinet.create_datapathid_from_host(event.datapath_id) next_dpid = self.get_remote_dpid_for_port(dpid, ports[0]) if(next_dpid): log.debug("Got FlowTracer stats reply from %s", dpid ) log.debug("Querying %s", next_dpid) self.pending_query_xid = self.send_flow_stats_request(next_dpid, \ self.match) else: log.debug("TRACE END") # Add last port (to host) self.current_path.append(str(ports[0])) print self.current_path # Send complete path to GUI self.send_to_gui("highlight", self.current_path) # Reset path self.current_path = [] return CONTINUE
def send_change(self, dpid_int, port_no, str_params): if (len(str_params) == 0): ret = self.ctxt.send_del_snat(dpid_int, port_no) else: external_prefix_arr = str_params[0].split("/") ip_start = c_ntohl(create_ipaddr(str(external_prefix_arr[0])).addr) if len(external_prefix_arr) > 1: # this is a prefix, not a single IP address prefix_len = int(external_prefix_arr[1]) ip_start = ip_start & (U32_ALL << (32 - prefix_len)) ip_end = ip_start | (U32_ALL >> prefix_len) else: ip_end = ip_start mac_str = str_params[4] if mac_str == "": mac_str = u"00:00:00:00:00:00" mac_addr = create_eaddr(mac_str.encode('utf-8')) # for now, the UI does not set restrictions on the # external ports used. tcp_start = 0 tcp_end = 0 udp_start = 0 udp_end = 0 ret = self.ctxt.send_add_snat(dpid_int, port_no, ip_start, ip_end, tcp_start, tcp_end, udp_start, udp_end, mac_addr) if (ret): lg.error("add/delete cmd snat failed with code = %s" % ret)
def send_change(self,dpid_int, port_no, str_params): if(len(str_params) == 0): ret = self.ctxt.send_del_snat(dpid_int,port_no) else: external_prefix_arr = str_params[0].split("/") ip_start = c_ntohl(create_ipaddr(str(external_prefix_arr[0])).addr) if len(external_prefix_arr) > 1: # this is a prefix, not a single IP address prefix_len = int(external_prefix_arr[1]) ip_start = ip_start & (U32_ALL << (32 - prefix_len)) ip_end = ip_start | (U32_ALL >> prefix_len) else: ip_end = ip_start mac_str = str_params[4] if mac_str == "": mac_str = u"00:00:00:00:00:00" mac_addr = create_eaddr(mac_str.encode('utf-8')) # for now, the UI does not set restrictions on the # external ports used. tcp_start = 0 tcp_end = 0 udp_start = 0 udp_end = 0 ret = self.ctxt.send_add_snat(dpid_int,port_no, ip_start,ip_end,tcp_start,tcp_end,udp_start,udp_end,mac_addr) if(ret): lg.error("add/delete cmd snat failed with code = %s" % ret)
def error_callback(sg, dpid, error_type, code, data, xid): logger.error("handling error from %s, xid = %d" % (dpid, xid)) intxid = c_ntohl(xid) if flowmod_callbacks.has_key(dpid): flows = flowmod_callbacks[dpid] if(flows.has_key(intxid)): flows[intxid]["result"] = FWDCTL_FAILURE flows[intxid]["error"] = {} flows[intxid]["error"]["type"] = error_type flows[intxid]["error"]["code"] = code
def error_callback(nddi, dpid, error_type, code, data, xid): logger.error("handling error from %s, xid = %d" % (dpid, xid)) intxid = c_ntohl(xid) if flowmod_callbacks.has_key(dpid): flows = flowmod_callbacks[dpid] if (flows.has_key(intxid)): flows[intxid]["result"] = FWDCTL_FAILURE flows[intxid]["error"] = {} flows[intxid]["error"]["type"] = error_type flows[intxid]["error"]["code"] = code
def __nwaddr_check__(addr): # should check if defined constant here if ((isinstance(addr, int) or isinstance(addr, long)) and addr >= 0 and addr <= 0xffffffff) \ or isinstance(addr, basestring): addr = create_ipaddr(addr) elif not isinstance(addr, ipaddr): return None if addr == None: return None return c_ntohl(addr.addr)
def handle_barrier_reply(self, dpid, xid): # find the pending route this xid belongs to intxid = c_ntohl(xid) for pending_route in self.pending_routes[:]: if intxid in pending_route: pending_route.remove(intxid) # If this was the last pending barrier_reply_xid in this route if len(pending_route) == 1: log.debug("All Barriers back, sending packetout") indatapath, inport, event = pending_route[0] self.routing.send_packet(indatapath, inport, \ openflow.OFPP_TABLE,event.buffer_id,event.buf,"", \ False, event.flow) self.pending_routes.remove(pending_route) return CONTINUE
def handle_barrier_reply(self, dpid, xid): # find the pending route this xid belongs to intxid = c_ntohl(xid) for pending_route in self.pending_routes[:]: if intxid in pending_route: pending_route.remove(intxid) # If this was the last pending barrier_reply_xid in this route if len(pending_route) == 1: log.debug("All Barriers back, sending packetout") indatapath, inport, event = pending_route[0] self.routing.send_packet(indatapath, inport, \ openflow.OFPP_TABLE,event.buffer_id,event.buf,"", \ False, event.flow) self.pending_routes.remove(pending_route) return STOP
def barrier_reply_callback(sg, dp_id, xid): intxid = c_ntohl(xid) if flowmod_callbacks.has_key(dp_id): flows = flowmod_callbacks[dp_id] if (flows.has_key(intxid)): flows[intxid]["status"] = ANSWERED flows[intxid]["result"] = FWDCTL_SUCCESS if not flows[intxid].has_key("failed_flows"): flows[intxid]["failed_flows"] = [] flows[intxid]["failed_flows"] = [] xids = flows.keys() for x in xids: if (x < intxid): if (flows[x]["result"] == FWDCTL_FAILURE): flows[intxid]["result"] = FWDCTL_FAILURE flows[intxid]["failed_flows"].append(flows[x]) del flows[x] sg.barrier_reply(dp_id, xid)
def barrier_reply_callback(sg,dp_id,xid): intxid = c_ntohl(xid) if flowmod_callbacks.has_key(dp_id): flows = flowmod_callbacks[dp_id] if(flows.has_key(intxid)): flows[intxid]["status"] = ANSWERED flows[intxid]["result"] = FWDCTL_SUCCESS if not flows[intxid].has_key("failed_flows"): flows[intxid]["failed_flows"] = [] flows[intxid]["failed_flows"] = [] xids = flows.keys() for x in xids: if(x < intxid): if(flows[x]["result"] == FWDCTL_FAILURE): flows[intxid]["result"] = FWDCTL_FAILURE flows[intxid]["failed_flows"].append(flows[x]) del flows[x] sg.barrier_reply(dp_id,xid)
def barrier_reply_callback(nddi, dp_id, xid): intxid = c_ntohl(xid) if flowmod_callbacks.has_key(dp_id): flows = flowmod_callbacks[dp_id] if (flows.has_key(intxid)): flows[intxid]["status"] = ANSWERED flows[intxid]["result"] = FWDCTL_SUCCESS if not flows[intxid].has_key("failed_flows"): flows[intxid]["failed_flows"] = [] flows[intxid]["failed_flows"] = [] xids = flows.keys() for x in xids: if (x < intxid): if (flows[x]["result"] == FWDCTL_FAILURE): flows[intxid]["result"] = FWDCTL_FAILURE flows[intxid]["failed_flows"].append(flows[x]) del flows[x] nddi.rmqi_rpc.emit_signal('barrier_reply', 'OF.NOX.event', dpid=dp_id)
def barrier_reply_callback(nddi, dp_id, xid): intxid = c_ntohl(xid) if flowmod_callbacks.has_key(dp_id): flows = flowmod_callbacks[dp_id] if(flows.has_key(intxid)): flows[intxid]["status"] = ANSWERED flows[intxid]["result"] = FWDCTL_SUCCESS if not flows[intxid].has_key("failed_flows"): flows[intxid]["failed_flows"] = [] flows[intxid]["failed_flows"] = [] xids = flows.keys() for x in xids: if(x < intxid): if(flows[x]["result"] == FWDCTL_FAILURE): flows[intxid]["result"] = FWDCTL_FAILURE flows[intxid]["failed_flows"].append(flows[x]) del flows[x] nddi.rmqi_rpc.emit_signal('barrier_reply','OF.NOX.event', dpid=dp_id )
def handle_flow_stats_in(self, event): """ Extract 'action' from the matching flow entry in order to see find the next hop """ if c_ntohl(event.xid) == self.pending_query_xid: # See action(s) for this entry if len(event.flows) != 1: log.debug( "matched to more than one flow entry! this should not happen" ) ports = [] for action in event.flows[0]['actions']: if action['type'] == 0: ports.append(action['port']) #elif ADD other action types here dpid = netinet.create_datapathid_from_host(event.datapath_id) next_dpid = self.get_remote_dpid_for_port(dpid, ports[0]) if (next_dpid): log.debug("Got FlowTracer stats reply from %s", dpid) log.debug("Querying %s", next_dpid) self.pending_query_xid = self.send_flow_stats_request(next_dpid, \ self.match) else: log.debug("TRACE END") # Add last port (to host) self.current_path.append(str(ports[0])) print self.current_path # Send complete path to GUI self.send_to_gui("highlight", self.current_path) # Reset path self.current_path = [] return CONTINUE
return webservice.badRequest(request, "Invalid MAC address.") nwsrc = create_ipaddr(content['nwsrc']) nwdst = create_ipaddr(content['nwdst']) if nwsrc == None or nwdst == None: return webservice.badRequest(request, "Invalid IP address.") def cb(names): try: request.write(simplejson.dumps(names)) request.finish() except Exception, e: self.err(Failure(), request, "get_names", "Could not retrieve name mappings.") self.policy.authenticator.get_names(dp, port, dlsrc, c_ntohl(nwsrc.addr), dldst, c_ntohl(nwdst.addr), cb) return webservice.NOT_DONE_YET except Exception, e: return self.err(Failure(), request, "get_names", "Could not retrieve name mappings.") # Wrapper so doesn't return error if used as errback def unlock_policy(self, res): return self.policy.unlock_policy(res) def get_policy(self, request, data): try: d = self.policy.lock_policy() d.addCallback(self.__get_policy__, request) d.addBoth(self.unlock_policy)
dldst = create_eaddr(0) else: dldst = create_eaddr(self.dldst) if dldst == None: mako_args["name_err"] = "Invalid dldst." return self.render_tmpl(request, "policydebug.mako", args=mako_args) if self.nwsrc == '': nwsrc = create_ipaddr(0) else: nwsrc = create_ipaddr(self.nwsrc) if nwsrc == None: mako_args["name_err"] = "Invalid nwsrc." return self.render_tmpl(request, "policydebug.mako", args=mako_args) if self.nwdst == '': nwdst = create_ipaddr(0) else: nwdst = create_ipaddr(self.nwdst) if nwdst == None: mako_args["name_err"] = "Invalid nwdst." return self.render_tmpl(request, "policydebug.mako", args=mako_args) def cb(names): mako_args['names'] = names request.write(self.render_tmpl(request, "policydebug.mako", args=mako_args)) request.finish() self.policy.authenticator.get_names(dpsrc, inport, dlsrc, c_ntohl(nwsrc.addr), dldst, c_ntohl(nwdst.addr), cb) return server.NOT_DONE_YET
dldst = create_eaddr(content['dldst']) if dlsrc == None or dldst == None: return webservice.badRequest(request, "Invalid MAC address.") nwsrc = create_ipaddr(content['nwsrc']) nwdst = create_ipaddr(content['nwdst']) if nwsrc == None or nwdst == None: return webservice.badRequest(request, "Invalid IP address.") def cb(names): try: request.write(simplejson.dumps(names)) request.finish() except Exception, e: self.err(Failure(), request, "get_names", "Could not retrieve name mappings.") self.policy.authenticator.get_names(dp, port, dlsrc, c_ntohl(nwsrc.addr), dldst, c_ntohl(nwdst.addr), cb) return webservice.NOT_DONE_YET except Exception, e: return self.err(Failure(), request, "get_names", "Could not retrieve name mappings.") # Wrapper so doesn't return error if used as errback def unlock_policy(self, res): return self.policy.unlock_policy(res) def get_policy(self, request, data): try: d = self.policy.lock_policy() d.addCallback(self.__get_policy__, request) d.addBoth(self.unlock_policy)