Esempio n. 1
0
    def dohandshake(self, msg):
        """Function to carry out handshake

        Switch (hello) => hello + feature request
        Switch (feature reply) => DONE
        """
        if (msg.header.type == pyopenflow.OFPT_HELLO):
            sendmsg = pyopenflow.ofp_hello()
            self.send(sendmsg.pack())
            sendmsg = pyopenflow.ofp_header()
            sendmsg.type = pyopenflow.OFPT_FEATURES_REQUEST
            self.send(sendmsg.pack())

        elif (msg.header.type == pyopenflow.OFPT_FEATURES_REPLY):
            switch_feature = pyopenflow.ofp_switch_features()
            switch_feature.unpack(msg.message)
            self.dpid = switch_feature.datapath_id
            output.info("Connected to switch %x" % self.dpid,
                        self.__class__.__name__)
            self.handshake = True
            
        else:
            output.warn("Handshake should not handle message type "+\
                            pyopenflow.ofp_type[msg.header.type],
                        self.__class__.__name__)
Esempio n. 2
0
    def __init__(self, sock, msg):
        """Initialize

        @param sock reference to socket
        @param msg message
        """
        ofcomm.message.__init__(self, sock, msg)

        ##Features struct
        self.features = None
        
        if (self.header.type == pyof.OFPT_FEATURES_REPLY):
            self.features = pyof.ofp_switch_features()
            r = self.features.unpack(msg)
            while (len(r) >= pyof.OFP_PHY_PORT_BYTES):
                p = pyof.ofp_phy_port()
                r = p.unpack(r)
                self.features.ports.append(p)
            if (len(r) > 0):
                output.warn("Features reply is of irregular length with "+\
                                str(len(r))+" bytes remaining.",
                            self.__class__.__name__)
            output.dbg("Received switch features:\n"+\
                           self.features.show("\t"),
                       self.__class__.__name__)