def call_dts(sock, msg_obj, msg_type): header = dts_pb2.ControlRequest() header.type = msg_type header.id = sock.id_counter.next() # The chosen generic address to DTS addrSend = "DTS\x00\x00\x00" + getHwAddr(sock.getsockname()[0]) #invert addrRcv = addrSend[6:] + addrSend[:6] #print 'addrSend:', addrSend.encode('string-escape'), '\naddrRecv:', addrRcv.encode('string-escape') # borrar header_serial = header.SerializeToString() msg_serial = msg_obj.SerializeToString() sent = sock.send(addrSend, struct.pack("<H", len(header_serial)), header_serial, struct.pack("<H", len(msg_serial)), msg_serial) if sent != 0: # TODO: deal with the case the message to DTS doesn't # fit the ethernet frame pass # Wait for response resp_obj = dts_pb2.ControlResponse() found_resp = False while not found_resp: data = sock.recv_filter(addrRcv) for msg_buffer in buffer_splitter(data): resp_obj.ParseFromString(msg_buffer) print resp_obj.request_id print header.id if resp_obj.request_id == header.id: found_resp = True break return resp_obj
def call_dts(sock, msg_obj, msg_type): header = dts_pb2.ControlRequest() header.type = msg_type header.id = sock.id_counter.next() # The chosen generic address to DTS addr = "DTS\x00\x00\x00\x00\x00\x00\x00\x00\x00" header_serial = header.SerializeToString() msg_serial = msg_obj.SerializeToString() sent = sock.send(addr, struct.pack("<H", len(header_serial)), header_serial, struct.pack("<H", len(msg_serial)), msg_serial) if sent != 0: # TODO: deal with the case the message to DTS doesn't # fit the ethernet frame pass # Wait for response resp_obj = dts_pb2.ControlResponse() found_resp = False while not found_resp: data = sock.recv_filter(addr) for msg_buffer in buffer_splitter(data): resp_obj.ParseFromString(msg_buffer) #print resp_obj.request_id, header.id if resp_obj.request_id == header.id: found_resp = True break return resp_obj
def reply_request(success, request_id, event): # Build the response resp_msg = dts_pb2.ControlResponse() resp_msg.status = resp_msg.SUCCESS if success else resp_msg.FAILURE if request_id != None: resp_msg.request_id = request_id resp_msg = resp_msg.SerializeToString() # Send response back to the entity resp = of.ofp_packet_out() resp.data = ''.join( (DTSA.HEADER, struct.pack("<H", len(resp_msg)), resp_msg)) resp.actions.append(of.ofp_action_output(port=event.port)) event.connection.send(resp)
def reply_request(self, success, request_id, event, title_aggr=None, w=None): # Build the response resp_msg = dts_pb2.ControlResponse() resp_msg.status = resp_msg.SUCCESS if success else resp_msg.FAILURE if request_id != None: resp_msg.request_id = request_id if self.aggr and w: # reply for the second workspace attachment print 'title_aggr', title_aggr, 'flow', self.flow # Send FLOW_MOD to the swith that is ataching an entity title = w.title if title_aggr in workspaces_aggr: w2 = workspaces_aggr[title_aggr] else: log.info('Unknown aggregated workspace title') title_hash = hashlib.sha256(title).digest()[:12] title_hash_aggr = hashlib.sha256(title_aggr).digest()[:12] recvRule = of.ofp_flow_mod() recvRule.command = of.OFPFC_MODIFY_STRICT #recvRule.match.dl_type = 0x0880 # Causes conflicts with user-space switches recvRule.match.dl_dst = title_hash_aggr[:6] recvRule.match.dl_src = title_hash_aggr[6:] recvRule.match.dl_vlan = self.flow recvRule.actions.append( of.ofp_action_dl_addr.set_dst(title_hash[:6])) recvRule.actions.append( of.ofp_action_dl_addr.set_src(title_hash[6:])) recvRule.actions.append( of.ofp_action_enqueue(port=event.port, queue_id=1)) core.openflow.sendToDPID(event.dpid, recvRule) try: s = w.switches[event.dpid] except KeyError: s = w.WPSwitch(event.dpid) w.switches[s.dpid] = s if event.dpid == w2.path[-1]: s.used_ports.add( graph[w2.path[-1]][w2.path[w2.path.index(w2.path[-1]) - 1]]['ports'][w2.path[-1]]) else: s.used_ports.add( graph[w2.path[0]][w2.path[w2.path.index(w2.path[0]) + 1]]['ports'][w2.path[0]]) sendRule = of.ofp_flow_mod() sendRule.command = of.OFPFC_MODIFY_STRICT #sendRule.match.dl_type = 0x0880 # Causes conflicts with user-space switches sendRule.match.dl_dst = title_hash[:6] sendRule.match.dl_src = title_hash[6:] sendRule.actions.append( of.ofp_action_dl_addr.set_dst(title_hash_aggr[:6])) sendRule.actions.append( of.ofp_action_dl_addr.set_src(title_hash_aggr[6:])) sendRule.actions.append(of.ofp_action_vlan_vid(vlan_vid=self.flow)) for p in s.used_ports: sendRule.actions.append( of.ofp_action_enqueue(port=p, queue_id=1)) core.openflow.sendToDPID(event.dpid, sendRule) # Send FLOW_MOD to the switch that created the workspace switch1 = wks[w.title] print 'OZUUUUUU1', switch1.dpid, switch1.port, try: s = w.switches[switch1.dpid] except KeyError: s = w.WPSwitch(switch1.dpid) w.switches[s.dpid] = s if switch1.dpid == w2.path[0]: s.used_ports.add( graph[w2.path[0]][w2.path[w2.path.index(w2.path[0]) + 1]]['ports'][w2.path[0]]) else: s.used_ports.add( graph[w2.path[-1]][w2.path[w2.path.index(w2.path[-1]) - 1]]['ports'][w2.path[-1]]) sendRule = of.ofp_flow_mod() sendRule.command = of.OFPFC_MODIFY_STRICT #sendRule.match.dl_type = 0x0880 # Causes conflicts with user-space switches sendRule.match.dl_dst = title_hash[:6] sendRule.match.dl_src = title_hash[6:] sendRule.actions.append( of.ofp_action_dl_addr.set_dst(title_hash_aggr[:6])) sendRule.actions.append( of.ofp_action_dl_addr.set_src(title_hash_aggr[6:])) sendRule.actions.append(of.ofp_action_vlan_vid(vlan_vid=self.flow)) for p in s.used_ports: sendRule.actions.append( of.ofp_action_enqueue(port=p, queue_id=1)) core.openflow.sendToDPID(switch1.dpid, sendRule) recvRule = of.ofp_flow_mod() recvRule.command = of.OFPFC_MODIFY_STRICT #recvRule.match.dl_type = 0x0880 # Causes conflicts with user-space switches recvRule.match.dl_dst = title_hash_aggr[:6] recvRule.match.dl_src = title_hash_aggr[6:] recvRule.match.dl_vlan = self.flow recvRule.actions.append( of.ofp_action_dl_addr.set_dst(title_hash[:6])) recvRule.actions.append( of.ofp_action_dl_addr.set_src(title_hash[6:])) recvRule.actions.append( of.ofp_action_enqueue(port=event.port, queue_id=1)) core.openflow.sendToDPID(switch1.dpid, recvRule) resp_msg = resp_msg.SerializeToString() # Send response back to the entity resp = of.ofp_packet_out() if not self.wifi: # not wifi resp.data = ''.join( (DTSA.HEADER, struct.pack("<H", len(resp_msg)), resp_msg)) else: resp.data = ''.join( (self.addrResp, struct.pack("<H", len(resp_msg)), resp_msg)) resp.actions.append(of.ofp_action_output(port=event.port)) event.connection.send(resp)