Exemple #1
0
    def process_MPLS_frame(self, m_fr, i):
        inface = 1
        if self.decap_tbl_D:  #DL: MPLS decapsulation if there exists the destination host for the mpls package
            if self.decap_tbl_D[m_fr.dest]:
                packet = m_fr.packet
                inface = self.decap_tbl_D[m_fr.dest]
        else:  #DL: MPLS forwarding if there's no decapsulation needed then it will be pushed on and relabeled for the next router
            for in_lbl in self.frwd_tbl_D:
                if m_fr.label == in_lbl:
                    for interface in self.frwd_tbl_D[in_lbl]:
                        m_fr.label = self.frwd_tbl_D[in_lbl][interface]
                        inface = interface

        print('%s: processing MPLS frame "%s"' % (self, m_fr))
        # for now forward the frame out interface 1
        try:  #DL: If packet exists then we need to forward that network packet to the host
            if packet:
                try:
                    fr = LinkFrame('Network', packet.to_byte_S())
                    self.intf_L[inface].put(fr.to_byte_S(), 'out', True)
                    print('%s: forwarding frame "%s" from interface %d to %d' %
                          (self, fr, i, inface))
                except queue.Full:
                    print('%s: frame "%s" lost on interface %d' % (self, p, i))
                    pass

        except:  #DL: If that packet does not exist then we look to forward it along to the next router in the line
            try:
                fr = LinkFrame('MPLS', m_fr.to_byte_S())
                self.intf_L[inface].put(fr.to_byte_S(), 'out', True)
                print('%s: forwarding frame "%s" from interface %d to %d' %
                      (self, fr, i, inface))
            except queue.Full:
                print('%s: frame "%s" lost on interface %d' % (self, p, i))
                pass
Exemple #2
0
    def process_MPLS_frame(self, m_fr, i):
        interface = -1

        if int(m_fr.label) in self.decap_tbl_D:
            interface = self.decap_tbl_D[int(m_fr.label)]
            packet = m_fr.pkt
            fr = LinkFrame('Network', packet.to_byte_S())
            self.intf_L[interface].put(fr.to_byte_S(), 'out', True)
            print('%s: decapsulated frame "%s" from interface %d to %d' %
                  (self, fr, i, 1))
        else:
            check_tuple = (i, int(m_fr.label))
            tuple = self.frwd_tbl_D[check_tuple]
            interface = tuple[0]
            m_fr.label = tuple[1]

            print('%s: processing MPLS frame "%s"' % (self, m_fr))

            try:
                fr = LinkFrame('MPLS', m_fr.to_byte_S())
                self.intf_L[interface].put(fr.to_byte_S(), 'out', True)
                print('%s: forwarding frame "%s" from interface %d to %d' %
                      (self, fr, i, 1))
            except queue.Full:
                print('%s: frame "%s" lost on interface %d' % (self, fr, i))
                pass
    def process_MPLS_frame(self, m_fr, in_intf):
        print('\n%s: processing MPLS frame "%s"' % (self, m_fr))
        # if the router has a decapsulation table with specific label
        if self.decap_tbl_D.get(m_fr.label) is not None:  # Last Hop
            print("%s decapsulated packet." % self.name)
            # obtain network pack by decapsulation
            network_pkt = m_fr.packet
            in_label = m_fr.label
            intf_out = self.frwd_tbl_D[(in_intf, in_label)][0]
            try:
                fr = LinkFrame('Network', network_pkt)
                self.intf_L[intf_out].put(fr.to_byte_S(), 'out', True)
                print(
                    '%s: forwarding network packet "%s" from interface %d to %d'
                    % (self, fr, intf_out, 1))
            except queue.Full:
                print('%s: frame "%s" lost on interface %d' %
                      (self, m_fr, intf_out))
                pass
        # if no decapsulation, then forward
        else:
            try:
                in_label = m_fr.label
                out_label = self.frwd_tbl_D[(in_intf, in_label)][1]
                intf_out = self.frwd_tbl_D[(in_intf, in_label)][0]
                m_fr.label = out_label
                fr = LinkFrame('MPLS', m_fr.to_byte_S())
                self.intf_L[intf_out].put(fr.to_byte_S(), 'out', True)
                print('%s: forwarding frame "%s" from label %d to %d' %
                      (self, fr, int(in_label), int(out_label)))
            except queue.Full:
                print('%s: frame "%s" lost on interface %d' %
                      (self, m_fr, intf_out))

            pass
Exemple #4
0
    def process_MPLS_frame(self, m_fr, i):
        #TODO: implement MPLS forward, or MPLS decapsulation if this is the last hop router for the path
        print('%s: processing MPLS frame "%s"' % (self, m_fr.label))

        try:
            compare = list(self.decap_tbl_D)[0]
        except:
            compare = None

        if (m_fr.label==compare):
            print("Last Hop, Decapsulation")
            try:
                m_fr.label=self.decap_tbl_D[m_fr.label]#check the label and assign the corresponding destination
                fr = LinkFrame('Network', m_fr.to_byte_S())
                self.intf_L[2].put(fr.to_byte_S(), 'out', True)
                print('%s: forwarding packet "%s" from interface %d to %d' % (self, fr, i, 1))
            except queue.Full:
                print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
            pass

        else:
            print("Implement MPLS Forward")
            try:
                inlabel=m_fr.label
                outlabel=list(self.frwd_tbl_D[inlabel][i].keys())[0] #get out interface
                print(outlabel)
                inter=self.frwd_tbl_D[inlabel][i][outlabel] #get out label
                m_fr.label=outlabel
                fr = LinkFrame('MPLS', m_fr.to_byte_S())
                self.intf_L[inter].put(fr.to_byte_S(), 'out', True)
                print('%s: forwarding frame "%s" from label %d to %d' % (self, fr, int(inlabel), int(outlabel)))
            except queue.Full:
                print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
            pass
    def process_MPLS_frame(self, m_fr, i):
        #TODO: implement MPLS forward, or MPLS decapsulation if this is the last hop router for the path
        #print("*********** interface: ", self)
        #print("*********** interface number: ", i)
        print('%s: processing MPLS frame "%s"' % (self, m_fr))
        #print("UOUUOUUOOUOOUUOUOUOUOUOUOUOUUOOUUO", self, " ", i)
        if self.decap_tbl_D.get(
            (str(self), i), "no"
        ) != "no":  #check if the (interface, interface_number) is in the encap dict
            print(
                "* * * ** **** ** * * **** ** * ** ** * * *  let's decapsulate"
            )
            byte_s = m_fr.to_byte_S()
            pkt = NetworkPacket.from_byte_S(byte_s[3:])
            print("THIS IS THE PACKET", pkt)
            fr = LinkFrame('Network', pkt.to_byte_S())
            self.intf_L[2].put(fr.to_byte_S(), 'out', True)

        # for now forward the frame out interface 1
        else:
            try:
                label = m_fr.get_Label()
                #print(' %% % % % % % % % % %  % % % % % % %  %%', label)
                interface_n = self.frwd_tbl_D[str(self) + str(i)][2]
                fr = LinkFrame('MPLS', m_fr.to_byte_S())
                self.intf_L[interface_n].put(fr.to_byte_S(), 'out', True)
                print('%s: forwarding frame "%s" from interface %d to %d' %
                      (self, fr, interface_n, 1))
            except queue.Full:
                print('%s: frame "%s" lost on interface %d' % (self, p, i))
                pass
Exemple #6
0
 def process_MPLS_frame(self, m_fr, i):
     print('%s: processing MPLS frame "%s"' % (self, m_fr.__str__()))
     forward = self.frwd_tbl_D.get(i)
     if forward:
         pkt = m_fr
         fr = LinkFrame('MPLS', pkt.to_byte_S())
     decap = self.decap_tbl_D.get(i)
     if decap:
         pkt = NetworkPacket.from_byte_S(m_fr.data_S.__str__())
         print('%s: decapsulated packet "%s" from MPLS frame "%s"' % (self, pkt, m_fr))
         fr = LinkFrame('Network', pkt.to_byte_S())
     out = 1
     if self.name is 'RA':
         if i == 0: 
             out = 2
         else:
             out = 3
     elif self.name is 'RD':
         out = 2
     # for now forward the frame out interface 1
     try:
         self.intf_L[out].put(fr.to_byte_S(), 'out', True)
         print('%s: forwarding frame "%s" from interface %d to %d' % (self, fr, i, 1))
     except queue.Full:
         print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
         pass
Exemple #7
0
 def process_MPLS_frame(self, m_fr, i):
     #TODO: implement MPLS forward, or MPLS decapsulation if this is the last hop router for the path
     print("Label: " + m_fr.label)
     data = self.frwd_tbl_D.get(m_fr.label, '')
     #print("Data: " + data)
     if data != '':
         m_fr.label = data[0]
         m_fr.dst = data[1]
         interf = data[2]
         end = self.decap_tbl_D.get(m_fr.label, "CONTINUE")
         #print("END = " + end)
         print('%s: processing MPLS frame "%s"' % (self, m_fr))
         # for now forward the frame out interface 1
         try:
             if end != "CONTINUE":
                 pkt = m_fr.to_Network_Packet()
                 fr = LinkFrame('Network', pkt)
             else:
                 fr = LinkFrame('MPLS', m_fr.to_byte_S())
             self.intf_L[interf].put(fr.to_byte_S(), 'out', True)
             print('%s: forwarding frame "%s" from interface %d to %d' %
                   (self, fr, i, 1))
         except queue.Full:
             print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
             pass
     else:
         print('****************Could not forward data********************')
         print('label was ' + str(m_fr))
Exemple #8
0
 def udt_send(self, dst, data_S, priority=0):
     pkt = NetworkPacket(dst, data_S)
     #        print('sending packet "%s"' % (str(pkt)))
     #encapsulate network packet in a link frame (usually would be done by the OS)
     fr = LinkFrame('Network', pkt.to_byte_S())
     #enque frame onto the interface for transmission
     self.intf_L[0].put(fr.to_byte_S(), 'out')
Exemple #9
0
 def process_MPLS_frame(self, m_fr, i):
     #TODO: implement MPLS forward, or MPLS decapsulation if this is the last hop router for the path
     print('%s: processing MPLS frame "%s"' % (self, m_fr))
     try:
         if (self.decap_tbl_D[m_fr.dst] is "Y"):
             pkt = NetworkPacket(m_fr.dst, m_fr.data_S)
             fr = LinkFrame('Network', pkt.to_byte_S())
             self.intf_L[self.frwd_tbl_D[i][m_fr.dst]].put(
                 fr.to_byte_S(), 'out', True)
             print('%s: forwarding frame "%s" from interface %d to %d' %
                   (self, fr, i, 1))
         else:
             fr = LinkFrame('MPLS', m_fr.to_byte_S())
             self.intf_L[self.frwd_tbl_D[i][m_fr.dst]].put(
                 fr.to_byte_S(), 'out', True)
             print('%s: forwarding frame "%s" from interface %d to %d' %
                   (self, fr, i, 1))
     except queue.Full:
         print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
         pass
Exemple #10
0
    def process_MPLS_frame(self, m_fr, i):
        # out MPLS label for packet
        out_label_S = None
        # new interface for forwarding
        out_intf_I = None
        # label for link layer
        out_link_label_S = None
        # string version of packet to be encapsolated by link layer
        out_pkt_S = None
        # get label from MPLS frame
        in_label_S = m_fr.label_S
        # get payload from MPLS frame
        in_payload_S = m_fr.data_S

        print('%s: processing MPLS frame "%s"' % (self, m_fr))

        # get the key that we will be looking for in frwd_tbl_D and deap_tbl_D
        tbl_key = (in_label_S, i)
        # check to see if there is a rule for forwarding this packet
        if tbl_key in self.frwd_tbl_D.keys():
            # get new MPLS label
            out_label_S = self.frwd_tbl_D[tbl_key][0]
            # get new interface to forward packet
            out_intf_I = self.frwd_tbl_D[tbl_key][1]
            # set link label as 'MPLS'
            out_link_label_S = 'MPLS'
            # create string payload for link layer to forward
            out_pkt_S = MPLSFrame(out_label_S, in_payload_S).to_byte_S()
        # else, check to see if there is a rule for decapsulation
        elif tbl_key in self.decap_tbl_D.keys():
            # get new interface to forward packet
            out_intf_I = self.decap_tbl_D[tbl_key]
            # set link labe as 'Network'
            out_link_label_S = 'Network'
            # create string payload for link layer to forward
            out_pkt_S = in_payload_S
        # if nothing is defined, drop the packet
        else:
            print('%s: frame "%s" lost on interface %d' % (self, p, i))
            pass

        # for now forward the frame out interface 1
        try:
            fr = LinkFrame(out_link_label_S, out_pkt_S)
            self.intf_L[out_intf_I].put(fr.to_byte_S(), 'out', True)
            print('%s: forwarding frame "%s" from interface %d to %d' %
                  (self, fr, i, out_intf_I))
        except queue.Full:
            print('%s: frame "%s" lost on interface %d' % (self, p, i))
            pass
Exemple #11
0
 def process_MPLS_frame(self, m_fr, i):
     print('%s: processing MPLS frame "%s"' % (self, m_fr))
     dst = m_fr.dst
     try:
         # Continue using MPLS if there is no need to decapsulate
         if self.decap_tbl_D[dst] is 0:
             fr = LinkFrame('MPLS', m_fr.to_byte_S())
         else:
             fr = LinkFrame('Network', m_fr.to_byte_S()[m_fr.label_length:])
             print('%s: decapsulated packet "%s" as Network frame "%s"' %
                   (self, m_fr, fr))
         # Send out on interface from the forwarding table
         self.intf_L[self.frwd_tbl_D[dst][i]].put(fr.to_byte_S(), 'out',
                                                  True)
         print('%s: forwarding frame "%s" from interface %d to %d' %
               (self, fr, i, self.frwd_tbl_D[dst][i]))
     except queue.Full:
         print('%s: frame "%s" lost on interface %d' % (self, p, i))
         pass
Exemple #12
0
 def process_MPLS_frame(self, m_fr, i):
     #TODO: implement MPLS forward, or MPLS decapsulation if this is the last hop router for the path
     print('%s: processing MPLS frame "%s"' % (self, m_fr))
     ## From the label received, we determine where it's going
     tbl_D = self.frwd_tbl_D[m_fr.label]
     m_fr.label = tbl_D["outLabel"]
     outInterface = tbl_D["intf"]
     ##see if we can decapsulate
     try:
         if m_fr.label == tbl_D['dest']:
             fr = LinkFrame("Network", m_fr.frame)
         else:
             fr = LinkFrame("MPLS", m_fr.to_byte_S())
         # fr = LinkFrame('Network', m_fr.to_byte_S()) ##this is how it used to be set up. Always assume it was in there
         self.intf_L[outInterface].put(fr.to_byte_S(), 'out', True)
         print('%s: forwarding frame "%s" from interface %d to %d' %
               (self, fr, i, outInterface))
     except queue.Full:
         print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
         pass
 def process_MPLS_frame(self, m_fr, i):
     #TODO: implement MPLS forward, or MPLS decapsulation if this is the last hop router for the path
     print('%s: processing MPLS frame "%s"' % (self, m_fr))
     ## From the label received, we determine where it's going
     table = self.frwd_tbl_D[m_fr.label]
     m_fr.label = table["outLabel"]
     outIntf = table["interface"]
     #if the queue is not full, try to decapsulate
     try:
         #if the next hop is the destination then we can decapsulate the mpls frame
         if m_fr.label == table['dest']:
             print('%s: decapsulating MPLS frame "%s"' % (self, m_fr))
             fr = LinkFrame("Network", m_fr.frame)
         else:
             fr = LinkFrame("MPLS", m_fr.to_byte_S())
         self.intf_L[outIntf].put(fr.to_byte_S(), 'out', True)
         print('%s: forwarding frame "%s" from interface %d to %d' %
               (self, fr, i, outIntf))
     except queue.Full:
         print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
         pass
Exemple #14
0
    def process_MPLS_frame(self, m_fr, i):
        print('%s: processing MPLS frame "%s"' % (self, m_fr))
        ## From the label received, we determine where it's going

        inlabel = m_fr.label
        m_fr.label = self.frwd_tbl_D[inlabel][0]
        outInterface = self.frwd_tbl_D[inlabel][2]
        try:
            #decapsulate
            if m_fr.label == self.frwd_tbl_D[inlabel][1]:
                print("\nLAST HOP, DECAPSULATING\n")
                fr = LinkFrame("Network", m_fr.packet)
            else:
                #forward
                print("\nNOT LAST HOP, FORWARDING\n")
                fr = LinkFrame("MPLS", m_fr.to_byte_S())
            self.intf_L[outInterface].put(fr.to_byte_S(), 'out', True)
            print('%s: forwarding frame "%s" from interface %d to %d' %
                  (self, fr, i, outInterface))
        except queue.Full:
            print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
            pass
Exemple #15
0
 def process_network_packet(self, pkt, i):
     # create out label for packet and interface to send to
     out_label_S = None
     out_intf_I = None
     # check to see if interface is in encap_tbl_D
     if i in self.encap_tbl_D.keys():
         out_label_S = self.encap_tbl_D[i][0]
         out_intf_I = self.encap_tbl_D[i][1]
     m_fr = MPLSFrame(out_label_S, pkt.to_byte_S())
     print('%s: encapsulated packet "%s" as MPLS frame "%s"' %
           (self, pkt, m_fr))
     #send the encapsulated packet for processing as MPLS frame
     #        self.process_MPLS_frame(m_fr, out_inf_I)
     # send newly encapsulated MPLS frame
     try:
         fr = LinkFrame('MPLS', m_fr.to_byte_S())
         self.intf_L[out_intf_I].put(fr.to_byte_S(), 'out', True)
         print('%s: forwarding frame "%s" from interface %d to %d' %
               (self, fr, i, out_intf_I))
     except queue.Full:
         print('%s: frame "%s" lost on interface %d' % (self, p, i))
         pass
Exemple #16
0
    def process_MPLS_frame(self, m_fr, i):
        #TODO: implement MPLS forward, or MPLS decapsulation if this is the last hop router for the path

        print('%s: processing MPLS frame "%s"' % (self, m_fr))
        # for now forward the frame out interface 1
        outInterface = self.frwd_tbl_D[(m_fr.dst, i)][1]
        try:
            if i in self.decap_tbl_D:
                if self.decap_tbl_D[i] == m_fr.dst:
                    fr = LinkFrame('Network', m_fr.data_S)
                    #self.intf_L[outInterface].put(fr.to_byte_S(), 'out', True)
                    print('%s: forwarding frame "%s" from interface %d to %d' %
                          (self, fr, i, outInterface))

            else:
                fr = LinkFrame("MPLS", m_fr.to_byte_S())
            self.intf_L[outInterface].put(fr.to_byte_S(), 'out', 'True')
            print('%s: forwarding frame "%s" from interface %d to %d' %
                  (self, fr, i, outInterface))
        except queue.Full:
            print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
            pass
Exemple #17
0
 def process_network_packet(self, pkt, i):
     #TODO: encapsulate the packet in an MPLS frame based on self.encap_tbl_D
     #for now, we just relabel the packet as an MPLS frame without encapsulation
     if i in self.encap_tbl_D:
         if self.encap_tbl_D[i] == pkt.dst:
             m_fr = MPLSF(pkt.dst, pkt)
             print('%s: encapsulated packet "%s" as MPLS frame "%s"' %
                   (self, pkt, m_fr))
             #send the encapsulated packet for processing as MPLS frame
             self.process_MPLS_frame(m_fr, i)
             return
         elif i == 0 and pkt.dst == "H1":
             m_fr = MPLSF(pkt.dst, pkt)
             print('%s: encapsulated packet "%s" as MPLS frame "%s"' %
                   (self, pkt, m_fr))
             #send the encapsulated packet for processing as MPLS frame
             self.process_MPLS_frame(m_fr, i)
             return
     outInterface = self.frwd_tbl_D[(pkt.dst, i)][1]
     fr = LinkFrame('Network', pkt.data_S)
     self.intf_L[outInterface].put(fr.to_byte_S(), 'out', True)
     print('%s: forwarding frame "%s" from interface %d to %d' %
           (self, fr, i, 1))
Exemple #18
0
 def process_MPLS_frame(self, m_fr, i):
     # TODO: implement MPLS forward, or MPLS decapsulation if this is the last hop router for the path
     #print('%s: processing MPLS frame "%s"' % (self, m_fr))
     # for now forward the frame out interface 1
     try:
         # Initalize the output interface to -1
         output_interface = -1
         #checks if we need to decapsulate or not
         if i in self.decap_tbl_D:
             # print("Decapsulating Block;\nRouter name:", str(self.name), "\nString received:", str(m_fr.to_byte_s()))
             dst = m_fr.packet[2:7].strip('0')
             data_S = m_fr.packet[7:]
             fr = LinkFrame('Network',
                            NetworkPacket(dst, data_S).to_byte_S())
             output_interface = self.decap_tbl_D[i][m_fr.label]
         else:
             fr = LinkFrame('MPLS', m_fr.to_byte_s())
             output_interface = self.frwd_tbl_D[m_fr.label]
         self.intf_L[output_interface].put(fr.to_byte_S(), 'out', True)
         # print('%s: forwarding frame "%s" from interface %d to %d' % (self, fr, i, 1))
     except queue.Full:
         # print('%s: frame "%s" lost on interface %d' % (self, m_fr, i))
         pass
Exemple #19
0
 def process_network_packet(self, pkt, i):
     #TODO: encapsulate the packet in an MPLS frame based on self.encap_tbl_D
     #print("process_network_packet being called: ", self, pkt)
     #print("*********** interface: ", self)
     #print("*********** interface number: ", i)
     if self.encap_tbl_D.get(
         (str(self), i), "no"
     ) != "no":  #check if the (interface, interface_number) is in the encap dict
         print("*#*#*#*#*#**#*#*#*#*##**#*# let's encapsulate")
         labelTuple = self.frwd_tbl_D[str(self) + str(i)]
         label = labelTuple[0] + str(labelTuple[1])
         m_fr = MPLSFrame(pkt, label)
         print('%s: encapsulated packet "%s" as MPLS frame "%s"' %
               (self, pkt, m_fr))
         self.process_MPLS_frame(
             m_fr,
             i)  #This will still get treated as a network packet initially
     else:
         print("is this the last network packet?")
         fr = LinkFrame('Network', pkt.to_byte_S())
         self.intf_L[1].put(fr.to_byte_S(), 'out', True)
         print('%s: forwarding frame "%s" from interface %d to %d' %
               (self, fr, i, 1))
Exemple #20
0
    def process_MPLS_frame(self, m_packet, i):
        #TODO: implement MPLS forward, or MPLS decapsulation if this is the last hop router for the path
        #print('%s: processing MPLS frame "%s"' % (self, m_fr))
        # for now forward the frame out interface 1
        try:
            outInterface = -1
            if i in self.decap_tbl_D:
                # decapsulate
                #                print("DECAPSULATION BLOCK\nRouter name = %s\nString received = %s\n" % (str(self.name),m_packet.to_byte_S()))
                dst = m_packet.new_packet[2:7].strip('0')
                data_S = m_packet.new_packet[7:]
                fr = LinkFrame('Network',
                               NetworkPacket(dst, data_S).to_byte_S())
                outInterface = self.decap_tbl_D[i][m_packet.label]
            else:
                fr = LinkFrame('MPLS', m_packet.to_byte_S())
                outInterface = self.frwd_tbl_D[m_packet.label]

            self.intf_L[outInterface].put(fr.to_byte_S(), 'out', True)
            #print('%s: forwarding frame "%s" from interface %d to %d' % (self, fr, i, 1))

        except queue.Full:
            #print('%s: frame "%s" lost on interface %d' % (self, p, i))
            pass