Ejemplo n.º 1
0
    def _handle_ConnectionUp(self, event):
        sw = self.switches.get(event.dpid)
        sw_str = dpidToStr(event.dpid)
        self.con = event.connection
        self.mac = self.con.eth_addr
        log.info("Saw switch come up: %s", sw_str)
        name_str = self.t.id_gen(dpid=event.dpid).name_str()
        if name_str not in self.t.switches():
            log.warn("Ignoring unknown switch %s" % sw_str)
            return
        if sw is None:
            log.info("Added fresh switch %s" % sw_str)
            sw = Switch()
            self.switches[event.dpid] = sw
            sw.connect(event.connection)
        else:
            log.info("Odd - already saw switch %s come up" % sw_str)
            sw.connect(event.connection)
        sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

        if len(self.switches) == len(self.t.switches()):
            log.info("Woo!  All switches up")
            self.all_switches_up = True
            self._get_all_paths()
        if self.all_switches_up == True:
            self._do_probe()
Ejemplo n.º 2
0
  def _handle_ConnectionUp (self, event):
    sw = self.switches.get(event.dpid)
    sw_str = dpidToStr(event.dpid)
    log.info("Saw switch come up: %s", sw_str)
    name_str = self.t.id_gen(dpid = event.dpid).name_str()
    if name_str not in self.t.switches():
      log.warn("Ignoring unknown switch %s" % sw_str)
      return
    if sw is None:
      log.info("Added fresh switch %s" % sw_str)
      sw = Switch()
      self.switches[event.dpid] = sw
      sw.connect(event.connection)
    else:
      log.info("Odd - already saw switch %s come up" % sw_str)
      sw.connect(event.connection)
    sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

    if len(self.switches) == len(self.t.switches()):
      log.info("Woo!  All switches up")
      self.all_switches_up = True
      if self.mode == 'proactive':
        self._install_proactive_flows()
      if self.mode == 'hybrid':
        self._install_hybrid_static_flows()
Ejemplo n.º 3
0
    def _handle_ConnectionUp(self, event):

        sw = self.switches.get(event.dpid)
        sw_str = dpidToStr(event.dpid)
        log.info("Saw switch com up: %s", sw_str)
        name_str = self.t.id_gen(dpid=event.dpid).name_str()

        if name_str not in self.t.switches():
            log.warn("Ignoring unknown switch %s" % sw_str)
            return

        if sw is None:
            log.info("Added fresh switch %s" % sw_str)
            sw = Switch()
            self.switches[event.dpid] = sw
            sw.connect(event.connection)

        else:
            log.info("Odd - already saw switch %s come up" % sw_str)
            sw.connect(event.connection)
        sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

        if len(self.switches) == len(self.t.switches()):
            log.info("Woo! All switches up")
            self.all_switches_up = True

            self._save_paths()
            # log.info("self.routeTable : %s" % self.routeTable)

            start = time()
            self._install_paths()
            log.info("use %s seconds to install paths" % (time() - start))

            # the pre_install_paths should have been installed
            log.info("Woo! All paths ok")
Ejemplo n.º 4
0
    def _handle_ConnectionUp(self, event):
        sw = self.switches.get(event.dpid)
        sw_str = dpidToStr(event.dpid)
        sw_name = self.t.id_gen(dpid=event.dpid).name_str()
        self.macTable.clear()  #clear macTable when there is a new conection

        if sw_name not in self.t.switches():
            log.warn("Ignoring unknown switch %s" % sw_str)
            return

        if sw is None:
            log.info("Added a new switch %s" % sw_name)
            sw = Switch()
            self.switches[event.dpid] = sw
            sw.connect(event.connection)
        else:
            log.debug("Odd - already saw switch %s come up" % sw_str)
            sw.connect(event.connection)

        sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

        if len(self.switches) == len(self.t.switches()):
            log.info("All of the switches are up")
            if self.mode == 'proactive':
                self._install_proactive_flows()
                log.info("Routing is complete")
            self.all_switches_up = True
Ejemplo n.º 5
0
  def handle_FEATURES_REPLY (self, con, msg):
    connecting = con.connect_time == None
    con.features = msg
    con.original_ports._ports = set(msg.ports)
    con.ports._reset()
    con.dpid = msg.datapath_id

    nexus = core.OpenFlowConnectionArbiter.getNexus(con)
    if nexus is None:
      # Cancel connection
      con.info("No OpenFlow nexus for " +
              pox.lib.util.dpidToStr(msg.datapath_id))
      con.disconnect()
      return
    con.ofnexus = nexus
    con.ofnexus._connect(con)

    #TODO: Add a timeout for finish_connecting

    if con.ofnexus.miss_send_len is not None:
      con.send(of.ofp_set_config(miss_send_len =
                                    con.ofnexus.miss_send_len))
    if con.ofnexus.clear_flows_on_connect:
      con.send(of.ofp_flow_mod(match=of.ofp_match(),command=of.OFPFC_DELETE))

    self._barrier = of.ofp_barrier_request()
    con.send(self._barrier)
Ejemplo n.º 6
0
    def __init__(self, connection, transparent):
        self.connection = connection
        self.transparent = transparent
        self.sw_info = {}
        self.connection.send(of.ofp_set_config(miss_send_len=65535))
        # Vhost Demuxer
        self.vhost_id = ''
        for port in connection.features.ports:
            intf_name = port.name.split('-')
            if (len(intf_name) < 2):
                continue
            else:
                self.vhost_id = intf_name[
                    0]  #get the first part of vhost1-eth0
                intf_name = intf_name[1]
            if self.vhost_id not in self.sw_info.keys():
                self.sw_info[self.vhost_id] = {}
            #if intf_name in VHOST_HW[self.vhost_id].keys():
            self.sw_info[self.vhost_id][intf_name] = (
                ROUTER_IP_DICT[self.vhost_id][intf_name], port.hw_addr.toStr(),
                '10Gbps', port.port_no)
            print self.sw_info

        self.rtable = RTABLE
        # We want to hear Openflow PacketIn messages, so we listen
        self.listenTo(connection)
        self.listenTo(core.cs123_srhandler)
        core.cs123_ofhandler.raiseEvent(
            RouterInfo(self.sw_info[self.vhost_id], self.rtable[self.vhost_id],
                       self.vhost_id))
Ejemplo n.º 7
0
  def _handle_ConnectionUp (self, event):
    print "*****************ConnectionUp"
    sw = self.switches.get(event.dpid)
    sw_str = dpidToStr(event.dpid)
    log.info("Saw switch come up: %s", sw_str)
    found = False
    for i in range(1,6):
      if event.dpid == i:
        found = True
      for j in range(1,5):
        if event.dpid == (10 * i + j):
          found = True
    if not found :
      log.warn("Ignoring unknown switch %s" % sw_str)
      return
    if sw is None:
      log.info("Added fresh switch %s" % sw_str)
      sw = Switch()
      self.switches[event.dpid] = sw
      sw.connect(event.connection)
    else:
      log.info("Odd - already saw switch %s come up" % sw_str)
      sw.connect(event.connection)
    sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

    if len(self.switches) == 25:
      log.info("Woo!  All switches up")
      self.all_switches_up = True
Ejemplo n.º 8
0
    def __init__(self, connection):
        self.connection = connection
        self.dpid = connection.dpid % 1000
        log.debug("dpid=%s", self.dpid)
        swifaces = {}
        self.connection.send(of.ofp_set_config(miss_send_len=65535))
        for port in connection.features.ports:
            intf_name = port.name.split('-')
            if (len(intf_name) < 2):
                continue
            else:
                self.swid = intf_name[0]
                intf_name = intf_name[1]
            if port.name in IP_SETTING.keys():
                swifaces[intf_name] = (IP_SETTING[port.name][0],
                                       IP_SETTING[port.name][1],
                                       port.hw_addr.toStr(), port.port_no)
            else:
                swifaces[intf_name] = (None, None, None, port.port_no)

        # We want to hear OF PacketIn messages, so we listen
        self.listenTo(connection)

        self.listenTo(core.VNetHandler)
        core.VNetOFNetHandler.raiseEvent(
            VNetDevInfo(swifaces, self.swid, self.dpid))
Ejemplo n.º 9
0
  def handle_FEATURES_REPLY (self, con, msg):
    connecting = con.connect_time == None
    con.features = msg
    con.original_ports._ports = set(msg.ports)
    con.ports._reset()
    con.dpid = msg.datapath_id

    # If any port status messages come between now and when the connection is
    # actually up, buffer them to raise later.
    con._deferred_port_status = []

    nexus = core.OpenFlowConnectionArbiter.getNexus(con)
    if nexus is None:
      # Cancel connection
      con.info("No OpenFlow nexus for " +
              pox.lib.util.dpidToStr(msg.datapath_id))
      con.disconnect()
      return
    con.ofnexus = nexus

    #TODO: Add a timeout for finish_connecting

    if con.ofnexus.miss_send_len is not None:
      con.send(of.ofp_set_config(miss_send_len =
                                    con.ofnexus.miss_send_len))
    if con.ofnexus.clear_flows_on_connect:
      con.send(of.ofp_flow_mod(match=of.ofp_match(),command=of.OFPFC_DELETE))

    self._barrier = of.ofp_barrier_request()
    con.send(self._barrier)
Ejemplo n.º 10
0
    def handle_FEATURES_REPLY(self, con, msg):
        connecting = con.connect_time == None
        con.features = msg
        con.original_ports._ports = set(msg.ports)
        con.ports._reset()
        con.dpid = msg.datapath_id

        nexus = core.OpenFlowConnectionArbiter.getNexus(con)
        if nexus is None:
            # Cancel connection
            con.info("No OpenFlow nexus for " +
                     pox.lib.util.dpidToStr(msg.datapath_id))
            con.disconnect()
            return
        con.ofnexus = nexus
        con.ofnexus._connect(con)

        #TODO: Add a timeout for finish_connecting

        if con.ofnexus.miss_send_len is not None:
            con.send(
                of.ofp_set_config(miss_send_len=con.ofnexus.miss_send_len))
        if con.ofnexus.clear_flows_on_connect:
            con.send(
                of.ofp_flow_mod(match=of.ofp_match(), command=of.OFPFC_DELETE))

        self._barrier = of.ofp_barrier_request()
        con.send(self._barrier)
    def _handle_ConnectionUp(self, event):
        sw = self.switches.get(event.dpid)
        sw_str = dpidToStr(event.dpid)
        log.info("Saw switch come up: %s", sw_str)
        name_str = self.t.id_gen(dpid=event.dpid).name_str()
        if name_str not in self.t.switches():
            log.warn("Ignoring unknown switch %s" % sw_str)
            return
        if sw is None:
            log.info("Added fresh switch %s" % sw_str)
            sw = Switch()
            self.switches[event.dpid] = sw
            sw.connect(event.connection)
        else:
            log.info("Odd - already saw switch %s come up" % sw_str)
            sw.connect(event.connection)
        sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

        if len(self.switches) == len(self.t.switches()):
            log.info("Woo!  All switches up")
            self.all_switches_up = True
            if self.mode == 'proactive':
                self._install_proactive_flows()
            if self.mode == 'hybrid':
                self._install_hybrid_static_flows()
Ejemplo n.º 12
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())
Ejemplo n.º 13
0
 def __init__ (self, connection, transparent):
   # Switch we'll be adding L2 learning switch capabilities to
   self.connection = connection
   self.transparent = transparent
   self.sw_info = {}
   self.connection.send(of.ofp_set_config(miss_send_len = 65535))
   for port in connection.features.ports:
       intf_name = port.name.split('-')
       if(len(intf_name) < 2):
         continue
       else:
         intf_name = intf_name[1]
       if intf_name in ROUTER_IP.keys():
         self.sw_info[intf_name] = (ROUTER_IP[intf_name], port.hw_addr.toStr(), '10Gbps', port.port_no)
   self.rtable = RTABLE
   # We want to hear Openflow PacketIn messages, so we listen
   self.listenTo(connection)
   self.listenTo(core.cs144_srhandler)
   core.cs144_ofhandler.raiseEvent(RouterInfo(self.sw_info, self.rtable))
Ejemplo n.º 14
0
  def _handle_ConnectionUp (self, event):

      sw = self.switches.get(event.dpid)
      sw_str = dpidToStr(event.dpid)
      log.info("Saw switch com up: %s", sw_str)
      name_str = self.t.id_gen(dpid = event.dpid).name_str()

      if name_str not in self.t.switches():
          log.warn("Ignoring unknown switch %s" % sw_str)
          return

      if sw is None:
          log.info("Added fresh switch %s" % sw_str)
          sw = Switch()
          self.switches[event.dpid] = sw
          sw.connect(event.connection)

      else:
          log.info("Odd - already saw switch %s come up" % sw_str)
          sw.connect(event.connection)
      sw.connection.send(of.ofp_set_config(miss_send_len = MISS_SEND_LEN))
        
      if len(self.switches) == len(self.t.switches()):
          log.info("Woo! All switches up")
          self.all_switches_up = True

          self._save_paths()

          # log.info("self.routeTable : %s" % self.routeTable)

          # self._install_paths()

          log.info("Woo! All paths ok")

          # suppose here we have a traffic matrix
          # find the routing policies for this traffic matrix
          #for i in range(10):
          #    num_matrix = i
          #    self.test(num_matrix)
          self.input_traffic()
Ejemplo n.º 15
0
    def _handle_ConnectionUp(self, event):

        sw = self.switches.get(event.dpid)
        sw_str = dpidToStr(event.dpid)
        log.info("Saw switch com up: %s", sw_str)
        name_str = self.t.id_gen(dpid=event.dpid).name_str()

        if name_str not in self.t.switches():
            log.warn("Ignoring unknown switch %s" % sw_str)
            return

        if sw is None:
            log.info("Added fresh switch %s" % sw_str)
            sw = Switch()
            self.switches[event.dpid] = sw
            sw.connect(event.connection)

        else:
            log.info("Odd - already saw switch %s come up" % sw_str)
            sw.connect(event.connection)
        sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

        if len(self.switches) == len(self.t.switches()):
            log.info("Woo! All switches up")
            self.all_switches_up = True

            self._save_paths()

            # log.info("self.routeTable : %s" % self.routeTable)

            # self._install_paths()

            log.info("Woo! All paths ok")

            # suppose here we have a traffic matrix
            # find the routing policies for this traffic matrix
            #for i in range(10):
            #    num_matrix = i
            #    self.test(num_matrix)
            self.input_traffic()
Ejemplo n.º 16
0
    def _handle_ConnectionUp(self, event):
        sw = self.switches.get(event.dpid)
        sw_str = dpidToStr(event.dpid)
        sw_name = self.t.node_gen(dpid = event.dpid).name_str()
        
        if sw_name not in self.t.switches():
            log.warn("Ignoring unknown switch %s" % sw_str)
            return

        if sw is None:
            log.info("Added a new switch %s" % sw_name)
            sw = Switch()
            self.switches[event.dpid] = sw
            sw.connect(event.connection)
        else:
            log.debug("Odd - already saw switch %s come up" % sw_str)
            sw.connect(event.connection)

        sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

        if len(self.switches)==len(self.t.switches()):
            log.info("All of the switches are up")
            self.all_switches_up = True
Ejemplo n.º 17
0
    def _handle_ConnectionUp(self, event):
        sw = self.switches.get(event.dpid)
        sw_str = dpidToStr(event.dpid)
        sw_name = self.t.node_gen(dpid=event.dpid).name_str()

        if sw_name not in self.t.switches():
            log.warn("Ignoring unknown switch %s" % sw_str)
            return

        if sw is None:
            log.info("Added a new switch %s" % sw_name)
            sw = Switch()
            self.switches[event.dpid] = sw
            sw.connect(event.connection)
        else:
            log.debug("Odd - already saw switch %s come up" % sw_str)
            sw.connect(event.connection)

        sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

        if len(self.switches) == len(self.t.switches()):
            log.info("All of the switches are up")
            self.all_switches_up = True
Ejemplo n.º 18
0
    def _handle_ConnectionUp(self, event):
        sw = self.switches.get(event.dpid)
        sw_str = dpidToStr(event.dpid)
        sw_name = self.t.node_gen(dpid = event.dpid).name_str()

        if sw_name not in self.t.switches():
            log.warn("Ignoring unknown switch %s" % sw_str)
            return

        #log.info("A new switch came up: %s", sw_str)
        if sw is None:
            log.info("Added a new switch %s" % sw_name)
            sw = Switch()
            self.switches[event.dpid] = sw
            sw.connect(event.connection)

        sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

        if len(self.switches)==len(self.t.switches()):
            log.info("All of the switches are up")
            self.all_switches_up = True
            if self.statMonitorLock.locked():
                self.statMonitorLock.release()    
Ejemplo n.º 19
0
    def _handle_ConnectionUp(self, event):
        sw = self.switches.get(event.dpid)
        sw_str = dpidToStr(event.dpid)
        sw_name = self.t.node_gen(dpid=event.dpid).name_str()

        if sw_name not in self.t.switches():
            log.warn("Ignoring unknown switch %s" % sw_str)
            return

        #log.info("A new switch came up: %s", sw_str)
        if sw is None:
            log.info("Added a new switch %s" % sw_name)
            sw = Switch()
            self.switches[event.dpid] = sw
            sw.connect(event.connection)

        sw.connection.send(of.ofp_set_config(miss_send_len=MISS_SEND_LEN))

        if len(self.switches) == len(self.t.switches()):
            log.info("All of the switches are up")
            self.all_switches_up = True
            if self.statMonitorLock.locked():
                self.statMonitorLock.release()
Ejemplo n.º 20
0
    def handle_FEATURES_REPLY(self, con, msg):
        if msg.version not in self.allowed_versions:
            # It's likely you won't see this message because the other side will
            # not have sent a features reply if it doesn't support OF 1.0.
            con.err("OpenFlow version 0x%02x not supported" % (msg.version, ))
            con.disconnect()
            return
        connecting = con.connect_time == None
        con.features = msg
        con.original_ports._ports = set(msg.ports)
        con.ports._reset()
        con.dpid = msg.datapath_id

        # If any port status messages come between now and when the connection is
        # actually up, buffer them to raise later.
        con._deferred_port_status = []

        nexus = core.OpenFlowConnectionArbiter.getNexus(con)
        if nexus is None:
            # Cancel connection
            con.info("No OpenFlow nexus for " +
                     pox.lib.util.dpidToStr(msg.datapath_id))
            con.disconnect()
            return
        con.ofnexus = nexus

        #TODO: Add a timeout for finish_connecting

        if con.ofnexus.miss_send_len is not None:
            con.send(
                of.ofp_set_config(miss_send_len=con.ofnexus.miss_send_len))
        if con.ofnexus.clear_flows_on_connect:
            con.send(
                of.ofp_flow_mod(match=of.ofp_match(), command=of.OFPFC_DELETE))

        self._barrier = of.ofp_barrier_request()
        con.send(self._barrier)
Ejemplo n.º 21
0
 def handle_Conn_Up(self, event):
     event.connection.send(of.ofp_set_config(miss_send_len=self.packetSize))
Ejemplo n.º 22
0
def handle_FEATURES_REPLY (con, msg):
  connecting = con.connect_time == None
  con.features = msg
  con.original_ports._ports = set(msg.ports)
  con.ports._reset()
  con.dpid = msg.datapath_id

  if not connecting:
    con.ofnexus._connect(con)
    e = con.ofnexus.raiseEventNoErrors(FeaturesReceived, con, msg)
    if e is None or e.halt != True:
      con.raiseEventNoErrors(FeaturesReceived, con, msg)
    return

  nexus = core.OpenFlowConnectionArbiter.getNexus(con)
  if nexus is None:
    # Cancel connection
    con.info("No OpenFlow nexus for " +
             pox.lib.util.dpidToStr(msg.datapath_id))
    con.disconnect()
    return
  con.ofnexus = nexus
  con.ofnexus._connect(con)
  #connections[con.dpid] = con

  barrier = of.ofp_barrier_request()

  listeners = []

  def finish_connecting (event):
    if event.xid != barrier.xid:
      con.dpid = None
      con.err("failed connect")
      con.disconnect()
    else:
      con.info("connected")
      con.connect_time = time.time()
      e = con.ofnexus.raiseEventNoErrors(ConnectionUp, con, msg)
      if e is None or e.halt != True:
        con.raiseEventNoErrors(ConnectionUp, con, msg)
      e = con.ofnexus.raiseEventNoErrors(FeaturesReceived, con, msg)
      if e is None or e.halt != True:
        con.raiseEventNoErrors(FeaturesReceived, con, msg)
    con.removeListeners(listeners)
  listeners.append(con.addListener(BarrierIn, finish_connecting))

  def also_finish_connecting (event):
    if event.xid != barrier.xid: return
    if event.ofp.type != of.OFPET_BAD_REQUEST: return
    if event.ofp.code != of.OFPBRC_BAD_TYPE: return
    # Okay, so this is probably an HP switch that doesn't support barriers
    # (ugh).  We'll just assume that things are okay.
    finish_connecting(event)
  listeners.append(con.addListener(ErrorIn, also_finish_connecting))

  #TODO: Add a timeout for finish_connecting

  if con.ofnexus.miss_send_len is not None:
    con.send(of.ofp_set_config(miss_send_len =
                                  con.ofnexus.miss_send_len))
  if con.ofnexus.clear_flows_on_connect:
    con.send(of.ofp_flow_mod(match=of.ofp_match(),command=of.OFPFC_DELETE))

  con.send(barrier)

  """
Ejemplo n.º 23
0
Archivo: of_01.py Proyecto: Phant76/pox
def handle_FEATURES_REPLY(con, msg):
    connecting = con.connect_time == None
    con.features = msg
    con.original_ports._ports = set(msg.ports)
    con.ports._reset()
    con.dpid = msg.datapath_id

    if not connecting:
        con.ofnexus._connect(con)
        e = con.ofnexus.raiseEventNoErrors(FeaturesReceived, con, msg)
        if e is None or e.halt != True:
            con.raiseEventNoErrors(FeaturesReceived, con, msg)
        return

    nexus = core.OpenFlowConnectionArbiter.getNexus(con)
    if nexus is None:
        # Cancel connection
        con.info("No OpenFlow nexus for " +
                 pox.lib.util.dpidToStr(msg.datapath_id))
        con.disconnect()
        return
    con.ofnexus = nexus
    con.ofnexus._connect(con)
    #connections[con.dpid] = con

    barrier = of.ofp_barrier_request()

    listeners = []

    def finish_connecting(event):
        if event.xid != barrier.xid:
            con.dpid = None
            con.err("failed connect")
            con.disconnect()
        else:
            con.info("connected")
            con.connect_time = time.time()
            e = con.ofnexus.raiseEventNoErrors(ConnectionUp, con, msg)
            if e is None or e.halt != True:
                con.raiseEventNoErrors(ConnectionUp, con, msg)
            e = con.ofnexus.raiseEventNoErrors(FeaturesReceived, con, msg)
            if e is None or e.halt != True:
                con.raiseEventNoErrors(FeaturesReceived, con, msg)
        con.removeListeners(listeners)

    listeners.append(con.addListener(BarrierIn, finish_connecting))

    def also_finish_connecting(event):
        if event.xid != barrier.xid: return
        if event.ofp.type != of.OFPET_BAD_REQUEST: return
        if event.ofp.code != of.OFPBRC_BAD_TYPE: return
        # Okay, so this is probably an HP switch that doesn't support barriers
        # (ugh).  We'll just assume that things are okay.
        finish_connecting(event)

    listeners.append(con.addListener(ErrorIn, also_finish_connecting))

    #TODO: Add a timeout for finish_connecting

    if con.ofnexus.miss_send_len is not None:
        con.send(of.ofp_set_config(miss_send_len=con.ofnexus.miss_send_len))
    if con.ofnexus.clear_flows_on_connect:
        con.send(of.ofp_flow_mod(match=of.ofp_match(),
                                 command=of.OFPFC_DELETE))

    con.send(barrier)
    """
Ejemplo n.º 24
0
def handle_FEATURES_REPLY(con, msg):  #type:6
    print "jiazy: receive Features_Reply message\n"
    connecting = con.connect_time == None  #connect_time = None as default, so connecting = ture
    #print ("con.connect_time:",con.connect_time)
    con.features = msg
    #con.dpid = msg.dev_id
    con.dpid = msg.deviceId  #according to tianye
    con.port_num_received = 0

    if not connecting:
        con.ofnexus._connect(con)
        e = con.ofnexus.raiseEventNoErrors(FeaturesReceived, con, msg)
        if e is None or e.halt != True:
            con.raiseEventNoErrors(FeaturesReceived, con, msg)
        return

    #OpenFlowConnectionArbiter is defined and registered in openflow.__init__.py
    nexus = core.OpenFlowConnectionArbiter.getNexus(
        con)  # nexus = core.openflow (class OpenFlowNexus)
    #print ('fun handle_FEATURES_REPLY --> nexus', nexus)    # cc
    if nexus is None:
        # Cancel connection
        con.info("No OpenFlow nexus for " + pox.lib.util.dpidToStr(msg.dev_id))
        con.disconnect()
        return
    con.ofnexus = nexus
    con.ofnexus._connect(
        con)  # self._connections[con.dpid] = con (in class OpenFlowNexus)
    #connections[con.dpid] = con

    #barrier = of.ofp_barrier_request()
    #con.send(barrier)
    getGonfigReq = of.ofp_get_config_request()

    listeners = []

    def finish_connecting(event):
        if event.xid != getGonfigReq.xid:
            con.dpid = None
            con.err("failed connect")
            con.disconnect()
        else:
            """
            con.info("connected")
            con.connect_time = time.time()
            e = con.ofnexus.raiseEventNoErrors(ConnectionUp, con, msg)
            if e is None or e.halt != True:
                con.raiseEventNoErrors(ConnectionUp, con, msg)
            """
            e = con.ofnexus.raiseEventNoErrors(FeaturesReceived, con, msg)
            if e is None or e.halt != True:
                con.raiseEventNoErrors(FeaturesReceived, con, msg)
        con.removeListeners(listeners)

    listeners.append(con.addListener(GetConfigReply, finish_connecting))

    def also_finish_connecting(event):
        if event.xid != getGonfigReq.xid: return
        if event.ofp.type != of.OFPET_BAD_REQUEST: return
        if event.ofp.code != of.OFPBRC_BAD_TYPE: return
        # Okay, so this is probably an HP switch that doesn't support barriers
        # (ugh).  We'll just assume that things are okay.
        finish_connecting(event)

    listeners.append(con.addListener(ErrorIn, also_finish_connecting))

    #TODO: Add a timeout for finish_connecting

    #print ('con.ofnexus.miss_send_len',con.ofnexus.miss_send_len)  #cc
    if con.ofnexus.miss_send_len is not None:
        #con.send(of.ofp_set_config(miss_send_len = con.ofnexus.miss_send_len))
        con.send(of.ofp_set_config(miss_send_len=0xffff))

    con.send(getGonfigReq)