Ejemplo n.º 1
0
    def __init__(self, connection, transparent):
        # Switch we'll be adding L2 learning switch capabilities to
        self.connection = connection
        self.transparent = transparent
        self.dpid = connection.dpid % 1000
        log.debug("dpid=%s", self.dpid)
        self.sw_info = {}
        self.connection.send(of.ofp_switch_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():
                self.sw_info[intf_name] = (IP_SETTING[port.name][0],
                                           IP_SETTING[port.name][1],
                                           port.hw_addr.toStr(), '10Gbps',
                                           port.port_no)


#    self.rtable = RTABLE[self.swid]
        self.rtable = []
        # We want to hear Openflow PacketIn messages, so we listen
        self.listenTo(connection)
        self.listenTo(core.cs640_srhandler)
        core.cs640_ofhandler.raiseEvent(
            RouterInfo(self.sw_info, self.rtable, self.swid, self.dpid))
Ejemplo n.º 2
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_switch_config(miss_send_len = 65535))
   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] = (VHOST_HW[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.cs144_srhandler)
   core.cs144_ofhandler.raiseEvent(RouterInfo(self.sw_info[self.vhost_id], self.rtable[self.vhost_id], self.vhost_id))
Ejemplo n.º 3
0
def handle_FEATURES_REPLY(con, msg):
    con.features = msg
    con.dpid = msg.datapath_id
    openflowHub._connections[con.dpid] = con

    if openflowHub.miss_send_len is not None:
        con.send(of.ofp_switch_config(miss_send_len=openflowHub.miss_send_len))
    if openflowHub.clear_flows_on_connect:
        con.send(of.ofp_flow_mod(match=of.ofp_match(),
                                 command=of.OFPFC_DELETE))
    barrier = of.ofp_barrier_request()
    con.send(barrier)

    def finish_connecting(event):
        if event.xid != barrier.xid:
            con.dpid = None
            con.err("Failed connect for " +
                    pox.lib.util.dpidToStr(msg.datapath_id))
            con.disconnect()
        else:
            con.info("Connected to " + pox.lib.util.dpidToStr(msg.datapath_id))
            #for p in msg.ports: print(p.show())
            openflowHub.raiseEventNoErrors(ConnectionUp, con, msg)
            con.raiseEventNoErrors(ConnectionUp, con, msg)
        return EventHaltAndRemove

    con.addListener(BarrierIn, finish_connecting)
Ejemplo n.º 4
0
def handle_FEATURES_REPLY(con, msg):
    connecting = con.connect_time == None
    con.features = msg
    con.dpid = msg.datapath_id

    if not connecting:
        con.ofnexus._connect(con)
        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 for " +
                    pox.lib.util.dpidToStr(msg.datapath_id))
            con.disconnect()
        else:
            con.info("Connected to " + pox.lib.util.dpidToStr(msg.datapath_id))
            import time
            con.connect_time = time.time()
            #for p in msg.ports: print(p.show())
            con.ofnexus.raiseEventNoErrors(ConnectionUp, con, msg)
            con.raiseEventNoErrors(ConnectionUp, 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_switch_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)
  def __init__ (self, connection):
    self.connection = connection
    self.dpid = connection.dpid % 1000
    log.debug("dpid=%s", self.dpid)
    swifaces = {}
    self.connection.send(of.ofp_switch_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.º 6
0
 def __init__(self, connection, transparent):
     # Switch we'll be adding L2 learning switch capabilities to
     hwinfos = {}
     self.connection = connection
     self.transparent = transparent
     self.sw_info = {}
     self.connection.send(of.ofp_switch_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]
         hwinfos.setdefault(intf_name, port.hw_addr.toStr())
         if intf_name in ROUTER_IP.keys():
             self.sw_info[intf_name] = (ROUTER_IP[intf_name],
                                        port.hw_addr.toStr(), '10Gbps',
                                        port.port_no)
     output = open("./HWINFOS_TEMP", "w")
     output.write(json.dumps(hwinfos))
     output.close()
     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.º 7
0
Archivo: of_01.py Proyecto: apanda/pox
def handle_FEATURES_REPLY (con, msg):
  con.features = msg
  con.dpid = msg.datapath_id
  openflowHub._connections[con.dpid] = con

  if openflowHub.miss_send_len is not None:
    con.send(of.ofp_switch_config(miss_send_len = openflowHub.miss_send_len))
  if openflowHub.clear_flows_on_connect:
    con.send(of.ofp_flow_mod(match=of.ofp_match(), command=of.OFPFC_DELETE))
  barrier = of.ofp_barrier_request()
  con.send(barrier)

  def finish_connecting (event):
    if event.xid != barrier.xid:
      con.dpid = None
      con.err("Failed connect for " + pox.lib.util.dpidToStr(msg.datapath_id))
      con.disconnect()
    else:
      con.info("Connected to " + pox.lib.util.dpidToStr(msg.datapath_id))
      #for p in msg.ports: print(p.show())
      openflowHub.raiseEventNoErrors(ConnectionUp, con, msg)
      con.raiseEventNoErrors(ConnectionUp, con, msg)
    return EventHaltAndRemove

  con.addListener(BarrierIn, finish_connecting)
Ejemplo n.º 8
0
def handle_FEATURES_REPLY (con, msg):
  connecting = con.connect_time == None
  con.features = msg
  con.dpid = msg.datapath_id

  if not connecting:
    con.ofnexus._connect(con)
    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 for " + pox.lib.util.dpidToStr(
              msg.datapath_id))
      con.disconnect()
    else:
      con.info("Connected to " + pox.lib.util.dpidToStr(msg.datapath_id))
      import time
      con.connect_time = time.time()
      #for p in msg.ports: print(p.show())
      con.ofnexus.raiseEventNoErrors(ConnectionUp, con, msg)
      con.raiseEventNoErrors(ConnectionUp, 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_switch_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.º 9
0
def handle_FEATURES_REPLY (con, msg):
  connecting = con.connect_time == None
  con.features = msg
  con.dpid = msg.datapath_id

  if not connecting:
    con.ofnexus._connect(con)
    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()

  def finish_connecting (event):
    if event.xid != barrier.xid:
      con.dpid = None
      con.err("Failed connect for " + pox.lib.util.dpidToStr(
              msg.datapath_id))
      con.disconnect()
    else:
      con.info("Connected to " + pox.lib.util.dpidToStr(msg.datapath_id))
      import time
      con.connect_time = time.time()
      #for p in msg.ports: print(p.show())
      con.ofnexus.raiseEventNoErrors(ConnectionUp, con, msg)
      con.raiseEventNoErrors(ConnectionUp, con, msg)
    return EventHaltAndRemove

  con.addListener(BarrierIn, finish_connecting)

  if con.ofnexus.miss_send_len is not None:
    con.send(of.ofp_switch_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.º 10
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_switch_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.º 11
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_switch_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.CSE425_srhandler)
     core.CSE425_ofhandler.raiseEvent(RouterInfo(self.sw_info, self.rtable))
Ejemplo n.º 12
0
  def __init__ (self, connection, transparent):
    # Switch we'll be adding L2 learning switch capabilities to
    self.connection = connection
    self.transparent = transparent
    self.dpid = connection.dpid % 1000
    log.debug("dpid=%s", self.dpid)
    self.sw_info = {}
    self.connection.send(of.ofp_switch_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():
          self.sw_info[intf_name] = (IP_SETTING[port.name][0], IP_SETTING[port.name][1], port.hw_addr.toStr(), '10Gbps', port.port_no)
#    self.rtable = RTABLE[self.swid]
    self.rtable = []
    # We want to hear Openflow PacketIn messages, so we listen
    self.listenTo(connection)
    self.listenTo(core.cs640_srhandler)
    core.cs640_ofhandler.raiseEvent(RouterInfo(self.sw_info, self.rtable, self.swid, self.dpid))