def process_queues(self): isNotUsingPriorities = self.getQueuePriorities() for i in range(len(self.intf_L)): fr_S = None #make sure we are starting the loop with a blank frame fr_S = self.intf_L[i].get('in') #get frame from interface i if fr_S is None: continue # no frame to process yet #if isNotUsingPriorities is not None: # print str(self) + ' is not using priorities? ' + str(isNotUsingPriorities) #decapsulate the packet fr = LinkFrame.from_byte_S(fr_S) pkt_S = fr.data_S #process the packet as network, or MPLS if fr.type_S == "Network": p = NetworkPacket.from_byte_S(pkt_S) #parse a packet out # print 'NETWORK QUEUE ' + pkt_S self.process_network_packet(p, i, isNotUsingPriorities) elif fr.type_S == "MPLS": # TODO: handle MPLS frames # print 'MPLS QUEUE ' + pkt_S mplsPacket = MPLS.from_byte_S(pkt_S) #parse a frame out #for now, we just relabel the packet as an MPLS frame without encapsulation #m_fr = p #send the MPLS frame for processing self.process_MPLS_frame(mplsPacket, i) else: raise('%s: unknown frame type: %s' % (self, fr.type))
def udt_receive(self): fr_S = self.intf_L[0].get('in') if fr_S is None: return #decapsulate the network packet fr = LinkFrame.from_byte_S(fr_S) assert(fr.type_S == 'Network') #should be receiving network packets by hosts pkt_S = fr.data_S print('%s: received packet "%s"' % (self, pkt_S))
def sort_packet(self, frame): temp_packet = LinkFrame.from_byte_S(frame) temp_data = temp_packet.data_S if temp_packet.type_S == 'MPLS': m_fr = MPLSFrame.from_byte_S(temp_data) return m_fr.exp elif temp_packet.type_S == 'Network': packet = NetworkPacket.from_byte_S(temp_data) return packet.priority
def udt_receive(self): fr_S = self.intf_L[0].get('in') if fr_S is None: return #decapsulate the network packet fr = LinkFrame.from_byte_S(fr_S) assert(fr.type_S == 'Network') #should be receiving network packets by hosts pkt_S = fr.data_S #print('received packet = %s' % str(pkt_S)) print("\n(Host %s) received message: %s" % (str(self), pkt_S)) return pkt_S
def process_queues(self): count = 0 total = 0 for intf in self.intf_L: for integer in intf.total: total += 1 if int(integer) == 1: count += 1 print("\n" + self.name + ": has total of: " + str(total) + " packets in queue and: " + str(count) + " with high priority\n") for i in range(len(self.intf_L)): fr_S = None #make sure we are starting the loop with a blank frame fr = None temp = 0 flag = False size = self.intf_L[i].in_queue.qsize() while temp <= size: fr_S = self.intf_L[i].get('in') #get frame from interface i if fr_S is None: flag = True break # no frame to process yet elif temp < size: fr = LinkFrame.from_byte_S(fr_S) prio = fr.data_S[-1] if int(prio) != 1: self.intf_L[i].put(fr.to_byte_S(), 'in', True) else: print(self.name + " processing higher priority jobs") break temp += 1 if flag: continue #decapsulate the packet #fr = LinkFrame.from_byte_S(fr_S) pkt_S = fr.data_S #process the packet as network, or MPLS if fr.type_S == "Network": p = NetworkPacket.from_byte_S(pkt_S) #parse a packet out self.process_network_packet(p, i) elif fr.type_S == "MPLS": # TODO: handle MPLS frames # m_fr = MPLSFrame.from_byte_S(pkt_S) #parse a frame out m_fr = MPLSF.from_byte_S(pkt_S) #send the MPLS frame for processing self.process_MPLS_frame(m_fr, i) else: raise ('%s: unknown frame type: %s' % (self, fr.type))
def process_queues(self): for i in range(len(self.intf_L)): fr_S = None #make sure we are starting the loop with a blank frame fr_S = self.intf_L[i].get('in') #get frame from interface i if fr_S is None: continue # no frame to process yet #decapsulate the packet fr = LinkFrame.from_byte_S(fr_S) pkt_S = fr.data_S #process the packet as network, or MPLS if fr.type_S == "Network": p = NetworkPacket.from_byte_S(pkt_S) #parse a packet out self.process_network_packet(p, i) elif fr.type_S == "MPLS": m_fr = MPLSFrame.from_byte_S(pkt_S) #parse a frame out self.process_MPLS_frame(m_fr, i) else: raise('%s: unknown frame type: %s' % (self, fr.type))
def process_queues(self): for i in range(len(self.intf_L)): fr_S = None #make sure we are starting the loop with a blank frame fr_S = self.intf_L[i].get('in') #get frame from interface i if fr_S is None: continue # no frame to process yet #decapsulate the packet fr = LinkFrame.from_byte_S(fr_S) pkt_S = fr.data_S #process the packet as network, or MPLS if fr.type_S == "Network": p = NetworkPacket.from_byte_S(pkt_S) #parse a packet out self.process_network_packet(p, i) elif fr.type_S == "MPLS": # TODO: handle MPLS frames # m_fr = MPLSFrame.from_byte_S(pkt_S) #parse a frame out #for now, we just relabel the packet as an MPLS frame without encapsulation # DEBUGGIN: DECAPSULATE MPLS # ===================================================================================================== # mplsFrame = MPLSFrame(pkt_S) mpls_frame_s = mplsFrame.from_byte_S(pkt_S) if mpls_frame_s[0] is 'M': pkt_s = mpls_frame_s mplsFrame = MPLSFrame(mpls_frame_s) mpls_frame_s = mplsFrame.from_byte_S(pkt_s) print( '\n\t\t @@@@=> DECAPSULATE MPLS --- PARSE A FRAME OUT <=@@@@\n' '\t\t @@@@=> NODE [%s] --- got MPLS Frame: %s on INTF [%d] <=@@@@\n' '\t\t @@@@=> NODE [%s] --- packet after decapsulation: %s <=@@@@\n' % (self.name, pkt_S, i, self.name, mpls_frame_s)) # ===================================================================================================== # #m_fr = p m_fr = mplsFrame # m_fr = mpls_frame_s #send the MPLS frame for processing self.process_MPLS_frame(m_fr, i) else: raise ('%s: unknown frame type: %s' % (self, fr.type))
def print_queues(self): for interface in range(len(self.intf_L)): temp_list = [] priority_dict = {} while True: try: frame = self.intf_L[interface].out_queue.get(block=False) except queue.Empty: break else: temp_list.append(frame) temp_list.sort(key=self.sort_packet, reverse=True) while len(temp_list) != 0: temp_S = temp_list.pop(0) self.intf_L[interface].put(temp_S, 'out') temp_packet = LinkFrame.from_byte_S(temp_S) temp_data = temp_packet.data_S if temp_packet.type_S == 'MPLS': m_fr = MPLSFrame.from_byte_S(temp_data) packet = m_fr.pkt int_priority = int(packet.priority) if int_priority not in priority_dict: priority_dict[int_priority] = 1 else: priority_dict[int_priority] += 1 elif temp_packet.type_S == 'Network': packet = NetworkPacket.from_byte_S(temp_data) int_priority = int(packet.priority) if int_priority not in priority_dict: priority_dict[int_priority] = 1 else: priority_dict[int_priority] += 1 for key in priority_dict: print( '%s - Interface %d: Queue has %d packets with priority %d' % (self.name, interface, priority_dict[key], key))
def put(self, pkt, in_or_out, block=False): if in_or_out == 'out': fr = LinkFrame.from_byte_S(pkt) if fr.type_S == "Network": p = NetworkPacket.from_byte_S(fr.data_S) #parse a packet out if p.priority in self.queuesize: self.queuesize[p.priority] += 1 else: self.queuesize[p.priority] = 1 elif fr.type_S == "MPLS": m_fr = MPLSlabel.from_byte_S(fr.data_S) p = NetworkPacket.from_byte_S(m_fr.frame) if p.priority in self.queuesize: self.queuesize[p.priority] += 1 else: self.queuesize[p.priority] = 1 self.out_queue.put(pkt, block) else: self.in_queue.put(pkt, block)
def process_queues(self): for i in range(len(self.intf_L)): fr_S = None #make sure we are starting the loop with a blank frame fr_S = self.intf_L[i].get('in') #get frame from interface i if fr_S is None: continue # no frame to process yet #decapsulate the packet fr = LinkFrame.from_byte_S(fr_S) pkt_S = fr.data_S #process the packet as network, or MPLS if fr.type_S == "Network": p = NetworkPacket.from_byte_S(pkt_S) #parse a packet out self.process_network_packet(p, i) elif fr.type_S == "MPLS": # TODO: handle MPLS frames m_fr = MPLSFrame.from_byte_S(pkt_S) #parse a frame out #send the MPLS frame for processing self.process_MPLS_frame( m_fr, i, int(pkt_S[6]) ) # Added the priority field to the process method but not the frame itself (needed for lookups) else: raise ('%s: unknown frame type: %s' % (self, fr.type))
def process_queues(self): for i in range(len(self.intf_L)): fr_S = None #make sure we are starting the loop with a blank frame fr_S = self.intf_L[i].get('in') #get frame from interface i if fr_S is None: continue # no frame to process yet #decapsulate the packet fr = LinkFrame.from_byte_S(fr_S) pkt_S = fr.data_S #process the packet as network, or MPLS if fr.type_S == "Network": p = NetworkPacket.from_byte_S(pkt_S) #parse a packet out self.process_network_packet(p, i) elif fr.type_S == "MPLS": # TODO: handle MPLS frames print(pkt_S) m_fr = MPLSFrame.from_byte_S(pkt_S) #parse a frame out #for now, we just relabel the packet as an MPLS frame without encapsulation print("m_fr from process_queues ", m_fr) #m_fr = p #send the MPLS frame for processing self.process_MPLS_frame(m_fr, i) else: raise ('%s: unknown frame type: %s' % (self, fr.type))
def process_queues(self): for i in range(len(self.intf_L)): fr_S = None #make sure we are starting the loop with a blank frame fr_S = self.intf_L[i].get('in') #get frame from interface i if fr_S is None: continue # no frame to process yet priority = fr_S[1] #decapsulate the packet fr = LinkFrame.from_byte_S(fr_S) #pkt_S = fr.data_S if priority == '0': self.p0_queue.append(fr) else: self.p1_queue.append(fr) if (len(self.p1_queue) > 0): if self.p1_queue[0].type_S == "Network": pkt_S = self.p1_queue.pop(0).data_S p = NetworkPacket.from_byte_S(pkt_S) #parse a packet out self.process_network_packet(p, i) elif self.p1_queue[0].type_S == "MPLS": pkt_S = self.p1_queue.pop(0).data_S m_fr = MPLSFrame.from_byte_S(pkt_S) self.process_MPLS_frame(m_fr, i) else: raise ('%s: unknown frame type: %s' % (self, fr.type)) else: if self.p0_queue[0].type_S == "Network": pkt_S = self.p0_queue.pop(0).data_S p = NetworkPacket.from_byte_S(pkt_S) #parse a packet out self.process_network_packet(p, i) elif self.p0_queue[0].type_S == "MPLS": pkt_S = self.p0_queue.pop(0).data_S m_fr = MPLSFrame.from_byte_S(pkt_S) self.process_MPLS_frame(m_fr, i) else: raise ('%s: unknown frame type: %s' % (self, fr.type))