예제 #1
0
  def __init__ (self, io_worker):
    self.io_worker = io_worker
    self.io_worker.rx_handler = self.read
    self.controller_id = io_worker.socket.getpeername()
    self.error_handler = None
    OFConnection.ID += 1
    self.ID = OFConnection.ID
    self.log = logging.getLogger("ControllerConnection(id=%d)" % (self.ID,))
    self.unpackers = make_type_to_unpacker_table()

    self.on_message_received = None
예제 #2
0
import datetime
import time
from pox.lib.socketcapture import CaptureSocket
import pox.openflow.debug
from pox.openflow.util import make_type_to_unpacker_table
from pox.openflow import *
import pdb
log = core.getLogger()

import socket
import select

# List where the index is an OpenFlow message type (OFPT_xxx), and
# the values are unpack functions that unpack the wire format of that
# type into a message object.
unpackers = make_type_to_unpacker_table()

try:
  PIPE_BUF = select.PIPE_BUF
except:
  try:
    # Try to get it from where PyPy (sometimes) has it
    import IN
    PIPE_BUF = IN.PIPE_BUF
  except:
    # (Hopefully) reasonable default
    PIPE_BUF = 512

import pox.openflow.libopenflow_01 as of

import threading
예제 #3
0
    def __init__(self, url, switch_connection, vlan, open_on_create=True):
        threading.Thread.__init__(self)
        self._running = False
        self._vlan = int(vlan)

        self.ofp_msgs = make_type_to_unpacker_table()
        self.ofp_handlers = {
            # Reactive handlers
            ofp_type_rev_map['OFPT_HELLO'] : self._receive_hello,
            ofp_type_rev_map['OFPT_ECHO_REQUEST'] : self._receive_echo,
            ofp_type_rev_map['OFPT_FEATURES_REQUEST'] : \
                self._receive_features_request,
            ofp_type_rev_map['OFPT_FLOW_MOD'] : self._receive_flow_mod,
            ofp_type_rev_map['OFPT_PACKET_OUT'] : self._receive_packet_out,
            ofp_type_rev_map['OFPT_BARRIER_REQUEST'] : \
                self._receive_barrier_request,
            ofp_type_rev_map['OFPT_GET_CONFIG_REQUEST'] : \
                self._receive_get_config_request,
            ofp_type_rev_map['OFPT_SET_CONFIG'] : self._receive_set_config,
            ofp_type_rev_map['OFPT_STATS_REQUEST'] : \
                self._receive_stats_request,
            ofp_type_rev_map['OFPT_VENDOR'] : self._receive_vendor,
            # Proactive responses
            ofp_type_rev_map['OFPT_ECHO_REPLY'] : self._receive_echo_reply
            # TODO: many more packet types to process
            }


        self._switch_connection = switch_connection
        if  not hasattr(switch_connection, '_dpid'): pdb.set_trace()

        # The controller sees VMOC as a switch. And we want each
        # connection to a controller to have a different DPID (or controllers
        # get confused). So VMOC has a different connection to a controller
        # by VLAN. And a controller may connect to multiple VMOCs.
        # So we need to construct a DPID that is unique over the space
        # of VLAN and switch_DPID.
        #
        # Here's what we do.
        # DPID's are 64 bits, of which the lower 48 are MAC addresses
        # and the top 16 are 'implementer defined' (Openflow spec).
        # The MAC should be unique and (for the contoller to talk to VMOC
        # we don't need to maintain the switch implementation features.
        # The vlan is 3 hex digits or 12 bits. 
        # So we take the VLAN and put it at the top three hex bytes of
        # the switch's DPID to form the VMOC-Controller-VLAN-specific DPIC
        #
        # VLAN in top 3 hex chars
        # Switch DPID in lower 13 hex chars
        controller_connection_dpid = \
            ((self._vlan & 0xfff) << 48) + \
            (switch_connection._dpid & 0x000fffffffffffff)  
        self._dpid = controller_connection_dpid

        log.info("DPID = %d %x %x"% (self._vlan, switch_connection._dpid, self._dpid))


        self._url = url
        (host, port) = VMOCControllerConnection.parseURL(url)
        self._host = host;
        self._port = port
        self._sock = None

        # Make it optional to not open on create (for debugging at least)
        if open_on_create:
            self.open()
예제 #4
0
import datetime
import time
from pox.lib.socketcapture import CaptureSocket
import pox.openflow.debug
from pox.openflow.util import make_type_to_unpacker_table
from pox.openflow import *

log = core.getLogger()

import socket
import select

# List where the index is an OpenFlow message type (OFPT_xxx), and
# the values are unpack functions that unpack the wire format of that
# type into a message object.
unpackers = make_type_to_unpacker_table()

try:
    PIPE_BUF = select.PIPE_BUF
except:
    try:
        # Try to get it from where PyPy (sometimes) has it
        import IN
        PIPE_BUF = IN.PIPE_BUF
    except:
        # (Hopefully) reasonable default
        PIPE_BUF = 512

import pox.openflow.libopenflow_01 as of

import threading