Beispiel #1
0
def handle_HELLO(con, msg):  # S
    # con.msg("HELLO wire protocol " + hex(msg.version))

    # Send a features request
    print("receive Hello message")
    msg = of.ofp_features_request()
    con.send(msg)
Beispiel #2
0
def handle_HELLO(con, msg):  #S
    #con.msg("HELLO wire protocol " + hex(msg.version))

    # Send a features request
    #log.info("recv a hello msg")
    msg = of.ofp_features_request()
    con.send(msg)
	def _handle_PortStatus(self, event):
		"""
		The method sends features_request message every time it receives
		PortStatus message so that the object always contains upto date
		information of ports
		"""
		connection.send(ofp_features_request())
Beispiel #4
0
    def __init__(self, sock, send_hello=True):
        self._previous_stats = []

        self.ofnexus = _dummyOFNexus
        self.sock = sock
        self.buf = ''
        Connection.ID += 1
        self.ID = Connection.ID
        # TODO: dpid and features don't belong here; they should be eventually
        # be in topology.switch
        self.dpid = None
        self.features = None
        self.disconnected = False
        self.disconnection_raised = False
        self.connect_time = None
        self.idle_time = time.time()

        if send_hello:
            log.debug('sending of.ofp_hello')
            self.send(of.ofp_hello())
        else:
            log.debug('sending of.ofp_features_request')
            msg = of.ofp_features_request()
            log.debug(msg)
            self.send(msg)

        self.original_ports = PortCollection()
        self.ports = PortCollection()
        self.ports._chain = self.original_ports
Beispiel #5
0
def handle_HELLO (con, msg): #S
  #con.msg("HELLO wire protocol " + hex(msg.version))
  log.debug("-> Hello received")
  # Send a features request
  msg = of.ofp_features_request()
  log.debug("<- Feature request sent")
  con.send(msg)
Beispiel #6
0
def handle_HELLO(con, msg):  #S
    #con.msg("HELLO wire protocol " + hex(msg.version))

    # Send a features request
    "Enviar um pedido, recursos"
    msg = of.ofp_features_request()
    con.send(msg)
Beispiel #7
0
def handle_HELLO(con, msg):  #S
    #con.msg("HELLO wire protocol " + hex(msg.version))

    # Send a features request
    print("receive Hello message")
    msg = of.ofp_features_request()
    con.send(msg)
Beispiel #8
0
def handle_HELLO (con, msg): #S
  #con.msg("HELLO wire protocol " + hex(msg.version))

  # Send a features request
  msg = of.ofp_features_request()
  con.send(msg)
  print ("DJ---/pox/openflow/of_01.py handle_HELLO con:",con)
Beispiel #9
0
def _on_timer():

    for n in nodes:
        #Sends out requests to the network nodes
        core.openflow.getConnection(n.connection.dpid).send(of.ofp_features_request())
        n.connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
        n.connection.send(of.ofp_stats_request(body=of.ofp_aggregate_stats_request()))
        n.connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
Beispiel #10
0
def _check_ports (dpid):
  """
  Sends a features request to the given dpid
  """
  _dirty_switches.pop(dpid,None)
  con = core.openflow.getConnection(dpid)
  if con is None: return
  con.send(of.ofp_barrier_request())
  con.send(of.ofp_features_request())
  log.debug("Requested switch features for %s", str(con))
Beispiel #11
0
 def connect (self, connection):
   if connection is None:
     self.log.warn("Can't connect to nothing")
     return
   if self.dpid is None:
     self.dpid = connection.dpid
   assert self.dpid == connection.dpid
   if self.ports is None:
     self.ports = connection.features.ports
   self.disconnect()
   self.connection = connection
   self._listeners = self.listenTo(connection)
   self._connected_at = time.time()
   label = dpid_to_str(connection.dpid)
   self.log = log.getChild(label)
   self.log.debug("Connect %s" % (connection,))
   if self._id is None:
     if self.dpid not in switches_by_id and self.dpid <= 254:
       self._id = self.dpid
     else:
       self._id = TopoSwitch._next_id
       TopoSwitch._next_id += 1
     switches_by_id[self._id] = self
   self.network = IPAddr("10.%s.0.0" % (self._id,))
   self.mac = dpid_to_mac(self.dpid)
   con = connection
   log.debug("Disabling flooding for %i ports", len(con.ports))
   for p in con.ports.itervalues():
     if p.port_no >= of.OFPP_MAX: continue
     pm = of.ofp_port_mod(port_no=p.port_no,
                         hw_addr=p.hw_addr,
                         config = of.OFPPC_NO_FLOOD,
                         mask = of.OFPPC_NO_FLOOD)
     con.send(pm)
   con.send(of.ofp_barrier_request())
   con.send(of.ofp_features_request())
   self.send_table()
   def fix_addr (addr, backup):
     if addr is None: return None
     if addr is (): return IPAddr(backup)
     return IPAddr(addr)
   self.ip_addr = IPAddr("10.%s.0.1" % (self._id,))
   self.router_addr = None
   self.dns_addr = None 
   self.subnet = IPAddr("255.0.0.0")
   self.pools = {}
   for p in connection.ports:
     if p < 0 or p >= of.OFPP_MAX: continue
     self.pools[p] = [IPAddr("10.%s.%s.%s" % (self._id,p,n))
                      for n in range(1,255)]
   self.lease_time = 60 * 60
   self.offers = {}
   self.leases = {}
Beispiel #12
0
  def handle_HELLO (self, con, msg): #S
    # Send features and switch desc requests
    if not self._features_request_sent:
      self._features_request_sent = True
      fr = of.ofp_features_request()

      if self.request_description:
        ss = of.ofp_stats_request()
        ss.body = of.ofp_desc_stats_request()

        con.send(fr.pack() + ss.pack())
      else:
        con.send(fr)
Beispiel #13
0
    def handle_HELLO(self, con, msg):  #S
        # Send features and switch desc requests
        if not self._features_request_sent:
            self._features_request_sent = True
            fr = of.ofp_features_request()

            if self.request_description:
                ss = of.ofp_stats_request()
                ss.body = of.ofp_desc_stats_request()

                con.send(fr.pack() + ss.pack())
            else:
                con.send(fr)
  def connect (self, connection):
    if connection is None:
      self.log.warn("Can't connect to nothing")
      return
    if self.dpid is None:
      self.dpid = connection.dpid
    #reises an exception if not true
    assert self.dpid == connection.dpid
    if self.ports is None:
      self.ports = connection.features.ports
    self.disconnect()
    self.connection = connection
    self._listeners = self.listenTo(connection)
    self._connected_at = time.time()

    label = dpid_to_str(connection.dpid)
    self.log = log.getChild(label)
    self.log.debug("Connect %s" % (connection,))

    #assign an ID to the switch
    if self._id is None:
      if self.dpid not in switches_by_id and self.dpid <= 254:
        self._id = self.dpid
      else:
        self._id = RoutingSwitch._next_id
        RoutingSwitch._next_id += 1
      switches_by_id[self._id] = self
    #assign network address
    self.network = IPAddr("10.%s.0.0" % (self._id,))
    self.mac = dpid_to_mac(self.dpid)

    # Disable flooding
    con = connection
    log.debug("Disabling flooding for %i ports", len(con.ports))
    for p in con.ports.itervalues():
      if p.port_no >= of.OFPP_MAX: continue
      msg = of.ofp_port_mod(port_no=p.port_no, hw_addr=p.hw_addr, config = of.OFPPC_NO_FLOOD, mask = of.OFPPC_NO_FLOOD)
      con.send(msg)

    con.send(of.ofp_barrier_request())
    con.send(of.ofp_features_request())
    # Send thee initial forwarding table to the switch
    self.send_table()
    # Set IP address of the switch
    self.ip_addr = IPAddr("10.%s.0.1" % (self._id,))
Beispiel #15
0
def _check_ports(dpid):

    _dirty_switches.pop(dpid, None)
    con = core.openflow.getConnection(dpid)
    if con is None: return
    """
  Barrier (Barreira) : Barreira de solicitação / resposta mensagens 
  são utilizados pelo controlador para garantir dependências de mensagens
 foram cumpridos ou para receber notificações de operações concluídas .
  """
    con.send(of.ofp_barrier_request())
    """
  Features (Características): O controlador pode solicitar a identidade e as capacidades básicas de um switch através do envio
  um pedido de recursos ; o interruptor deve responder com uma características responder que especifica a identidade e básico
  capacidades da chave. Isto é comumente realizada mediante estabelecimento do canal OpenFlow .
  """
    con.send(of.ofp_features_request())
    log.debug("Requested switch features for %s", str(con))
Beispiel #16
0
 def check_socket(self):
     pkt_count = 0
     while True:
         pkt_count += 1
         buff = self.s.recv(100)
         pkt = of.ofp_header()
         pkt.unpack(buff)
         #print('[{}][check_socket]recved: ', len(buff))
         print('\n[{0}] received [{1}]byte data.'.format(pkt_count, len(buff)))
         print(pkt.show())
         if pkt.header_type == gini_of.OFPT_HELLO:  # OFPT_HELLO
             print("OFPT_HELLO msg: ")
             pkt = of.ofp_hello()
             pkt.unpack(buff)
             self.process_hello(pkt)
         elif pkt.header_type == gini_of.OFPT_ECHO_REQUEST:
             print("OFPT_ECHO_REPLY msg: ")
             pkt = of.ofp_echo_request()
             pkt.unpack(buff)
             self.process_echo_request(pkt)
         elif pkt.header_type == gini_of.OFPT_FEATURES_REQUEST:
             print("OFPT_FEATURES_REQUEST msg: ")
             pkt = of.ofp_features_request()
             pkt.unpack(buff)
             self.process_features_request(pkt)
         elif pkt.header_type == gini_of.OFPT_SET_CONFIG:
             print("OFPT_SET_CONFIG msg: ")
             pkt = of.ofp_set_config()
             pkt.unpack(buff)
             self.process_set_config(pkt)
         elif pkt.header_type == gini_of.OFPT_FLOW_MOD:
             print("OFPT_FLOW_MOD msg: ")
             pkt = giniclass_flow_mod()
             pkt.unpack(buff)
             self.process_flow_mod(pkt)
         elif pkt.header_type == gini_of.OFPT_BARRIER_REQUEST:
             print("OFPT_BARRIER_REQUEST msg: ")
             pkt = of.ofp_barrier_request()
             pkt.unpack(buff)
             self.process_barrier_request(pkt)
         else:
             print("Unknown type!: ", pkt.header_type, "details: ")
             print(pkt.show())
Beispiel #17
0
    def _realize(self):
        if self._port_out == self._port_out_cache: return

        # We really shouldn't need to get the connection here...
        con = core.openflow.connections.get(self.dpid)
        if con is None: return

        data = []
        for port_no, cfg in self._port_out.items():
            if port_no not in self.ports: continue
            if port_no not in con.ports: continue
            p = con.ports[port_no]
            pm = of.ofp_port_mod(port_no=p.port_no,
                                 hw_addr=p.hw_addr,
                                 config=cfg,
                                 mask=of.OFPPC_NO_FLOOD | of.OFPPC_NO_FWD)
            data.append(pm.pack())

        # We could probably handle the features stuff better
        data.append(of.ofp_features_request().pack())

        if self.send(b''.join(data)):
            self._port_out_cache = self._port_out
            self.log.info("Configured %s ports", len(data) - 1)
Beispiel #18
0
    def handle_HELLO(con, msg):  #S
        #con.msg("HELLO wire protocol " + hex(msg.version))

        # Send a features request
        msg = of.ofp_features_request()
        con.send(msg)
Beispiel #19
0
def handle_HELLO (con, msg): #S
  #con.msg("HELLO wire protocol " + hex(msg.version))

  # Send a features request
  msg = of.ofp_features_request()
  con.send(msg)
Beispiel #20
0
def timer_func():
    for n in nodes:
        core.openflow.getConnection(n.connection.dpid).send(of.ofp_features_request())
  def connect (self, connection):
    if connection is None:
      self.log.warn("Can't connect to nothing")
      return
    if self.dpid is None:
      self.dpid = connection.dpid
    assert self.dpid == connection.dpid
    if self.ports is None:
      self.ports = connection.features.ports
    self.disconnect()
    self.connection = connection
    self._listeners = self.listenTo(connection)
    self._connected_at = time.time()

    label = dpid_to_str(connection.dpid)
    self.log = log.getChild(label)
    self.log.debug("Connect %s" % (connection,))

    if self._id is None:
      if self.dpid not in switches_by_id and self.dpid <= 254:
        self._id = self.dpid
      else:
        self._id = TopoSwitch._next_id
        TopoSwitch._next_id += 1
      switches_by_id[self._id] = self

    self.network = IPAddr("10.%s.0.0" % (self._id,))
    self.mac = dpid_to_mac(self.dpid)

    # Disable flooding
    con = connection
    log.debug("Disabling flooding for %i ports", len(con.ports))
    for p in con.ports.itervalues():
      if p.port_no >= of.OFPP_MAX: continue
      pm = of.ofp_port_mod(port_no=p.port_no,
                          hw_addr=p.hw_addr,
                          config = of.OFPPC_NO_FLOOD,
                          mask = of.OFPPC_NO_FLOOD)
      con.send(pm)
    con.send(of.ofp_barrier_request())
    con.send(of.ofp_features_request())

    # Some of this is copied from DHCPD's __init__().
    self.send_table()

    def fix_addr (addr, backup):
      if addr is None: return None
      if addr is (): return IPAddr(backup)
      return IPAddr(addr)

    self.ip_addr = IPAddr("10.%s.0.1" % (self._id,))
    #self.router_addr = self.ip_addr
    self.router_addr = None
    self.dns_addr = None #fix_addr(dns_address, self.router_addr)

    self.subnet = IPAddr("255.0.0.0")
    self.pools = {}
    for p in connection.ports:
      if p < 0 or p >= of.OFPP_MAX: continue
      self.pools[p] = [IPAddr("10.%s.%s.%s" % (self._id,p,n))
                       for n in range(1,255)]

    self.lease_time = 60 * 60 # An hour
    #TODO: Actually make them expire :)

    self.offers = {} # Eth -> IP we offered
    self.leases = {} # Eth -> IP we leased
Beispiel #22
0
 def _refresh_features(self):
   # Not sure if this is strictly necessary; pulled from openflow/spanning_tree.py
   # We do this after we adjust link state via ofp_port_mod commands.
   SpanningTreeSwitch.logger.info('switch-{}: Refreshing features.'.format(self.dpid))
   self.connection.send(of.ofp_barrier_request())
   self.connection.send(of.ofp_features_request())