Example #1
0
    def openflowV1(self):

        # OF_HELLO switch <-> controller
        self.sendAndReceiveOF_HELLO_OPENFLOWV1()

        # OF_FEATURE switch <-> controller
        self.sendAndReceiveOF_FEATURE_OPENFLOWV1()
        return
        """
        port = PPort(100, "ff:ff:ff:ff:ff:00" , "test", 0, 0, 192 ,0,0,0)
        port.port_no = 200
        print( "add port : " + str(port.port_no))
        packed_data = portStatus( reason=portReason.OFPPR_ADD , desc=port )
        packed_data = packed_data.pack()
        self.s.send( packed_data )  
        """

        # init value
        data = None

        while(1):

            count = 0
            # receive OF_PACKET_OUT message
            while count < self.numberOfRetransmission :
                try:
                    data = self.s.recv(self.buffer_size)
                    data = unpack_message(data)
                    break
                except Exception as err:
                    count += 1
                    print( " 431 Switch ip " + self.switchIp + " handling run-time error of socket : " + str( err ) )
            
            if count == self.numberOfRetransmission :
                print( " 443 Switch ip " + self.switchIp + " socket don't receive data")
                sys.exit()
        
            if data.header.message_type.name == "OFPT_PACKET_OUT":
                
                
                self.checkStatusOfActivePort()
                # OF_PACKET_IN -> controller
                check = self.sendLLDPInOF_PACKET_IN_OPENFLOWV1( data )
                
                if not check :
                    print("send OFPT_ECHO_REQUEST")
                    packet = echoRequest().pack()
                    self.s.send(packet)
            
            """
            if data.header.message_type.name == "OFPT_ECHO_REQUEST":
                print("Send OFPT_ECHO_REPLY")
                packet = echoReply().pack()
                self.s.send(packet)
            """


            """
Example #2
0
    def openflowV1(self):

        # init value
        data = None
        checkData = None
        tempBytes = None

        # OF_HELLO switch <-> controller
        checkData, tempBytes = self.sendAndReceiveOF_HELLO_OPENFLOWV1()

        # OF_FEATURE switch <-> controller
        self.sendAndReceiveOF_FEATURE_OPENFLOWV1(checkData, tempBytes)
        """
        port = PPort(100, "ff:ff:ff:ff:ff:00" , "test", 0, 0, 192 ,0,0,0)
        port.port_no = 200
        print( "add port : " + str(port.port_no))
        packed_data = portStatus( reason=portReason.OFPPR_ADD , desc=port )
        packed_data = packed_data.pack()
        self.s.send( packed_data )  
        """

        while (1):

            #init value
            indexData = 0

            tempData = self.receiveDataFromSocket()
            self.checkStatusOfActivePort()

            while indexData < len(tempData):

                data = unpack_message(tempData[indexData:])
                if data.header.message_type.name == "OFPT_PACKET_OUT":

                    # OF_PACKET_IN -> controller
                    check = self.sendLLDPInOF_PACKET_IN_OPENFLOWV1(data)

                    if not check:
                        print("switch ip " + self.switchIp +
                              " send OFPT_ECHO_REQUEST")
                        packet = echoRequest().pack()
                        self.s.send(packet)

                indexData += data.header.length
            """
            if data.header.message_type.name == "OFPT_ECHO_REQUEST":
                print("Send OFPT_ECHO_REPLY")
                packet = echoReply().pack()
                self.s.send(packet)
            """
            """
Example #3
0
    def openflowV1(self):

        
        # OF_HELLO switch <-> controller
        self.sendAndReceiveOF_HELLO_OPENFLOWV1()

        # OF_FEATURE switch <-> controller
        self.sendAndReceiveOF_FEATURE_OPENFLOWV1()

        # init value
        data = None

        while(1):

            count = 0
            # receive OF_PACKET_OUT message
            while count < self.numberOfRetransmission :
                try:
                    data = self.s.recv(self.buffer_size)
                    data = unpack_message(data)
                    break
                except Exception as err:
                    count += 1
                    print( " 431 Switch ip " + self.switchIp + " handling run-time error of socket : " + str( err ) )
            
            if count == self.numberOfRetransmission :
                print( " 443 Switch ip " + self.switchIp + " socket don't receive data")
                sys.exit()
        
            if data.header.message_type.name == "OFPT_PACKET_OUT":
                
                self.receiveRemoteSwitchDataFromSnmpVersion2C()
                self.checkStatusOfActivePort()
                # OF_PACKET_IN -> controller
                check = self.sendLLDPInOF_PACKET_IN_OPENFLOWV1( data )
                
                if not check :
                    print("send OFPT_ECHO_REQUEST")
                    packet = echoRequest().pack()
                    self.s.send(packet)
            
            """
            if data.header.message_type.name == "OFPT_ECHO_REQUEST":
                print("Send OFPT_ECHO_REPLY")
                packet = echoReply().pack()
                self.s.send(packet)
            """


            """
Example #4
0
    def openflowV1(self):

        # init value
        data = None
        checkData = None
        tempBytes = None

        # OF_HELLO switch <-> controller
        checkData, tempBytes = self.sendAndReceiveOF_HELLO_OPENFLOWV1()

        # OF_FEATURE switch <-> controller
        self.sendAndReceiveOF_FEATURE_OPENFLOWV1(checkData, tempBytes)
        """
        port = PPort(100, "ff:ff:ff:ff:ff:00" , "test", 0, 0, 192 ,0,0,0)
        port.port_no = 200
        print( "add port : " + str(port.port_no))
        packed_data = portStatus( reason=portReason.OFPPR_ADD , desc=port )
        packed_data = packed_data.pack()
        self.s.send( packed_data )  
        """
        count = 0
        while (1):

            #init value
            indexData = 0
            tempData = None
            try:
                tempData = self.s.recv(self.buffer_size)
            except Exception as err:
                count += 1

            if tempData != None:

                self.checkStatusOfActivePort()

                while indexData < len(tempData):

                    data = unpack_message(tempData[indexData:])
                    if data.header.message_type.name == "OFPT_PACKET_OUT":

                        # OF_PACKET_IN -> controller
                        check = self.sendLLDPInOF_PACKET_IN_OPENFLOWV1(data)
                        #print("send of_packet_in")
                        if check:
                            count = 0
                        else:
                            count += 1
                        """
                        if not check :
                            print("switch ip " + self.switchIp + " send OFPT_ECHO_REQUEST")
                            packet = echoRequest().pack()
                            self.s.send(packet)
                        """

                    #pox
                    if data.header.message_type.name == "OFPT_BARRIER_REQUEST":
                        count = 0
                        packet = BarReply()
                        packet.header.xid = data.header.xid
                        packet = packet.pack()
                        self.s.send(packet)

                    indexData += data.header.length

            if count == 2:
                count = 0
                #print("switch ip " + self.switchIp + " send OFPT_ECHO_REQUEST")
                packet = echoRequest().pack()
                self.s.send(packet)
            """
            if data.header.message_type.name == "OFPT_ECHO_REQUEST":
                print("Send OFPT_ECHO_REPLY")
                packet = echoReply().pack()
                self.s.send(packet)
            """
            """