Пример #1
0
 def _create_lacp(self, datapath, port, req):
     """create a LACP packet."""
     actor_system = datapath.ports[datapath.ofproto.OFPP_LOCAL].hw_addr
     res = slow.lacp(
         actor_system_priority=0xffff,
         actor_system=actor_system,
         actor_key=req.actor_key,
         actor_port_priority=0xff,
         actor_port=port,
         actor_state_activity=req.LACP_STATE_PASSIVE,
         actor_state_timeout=req.actor_state_timeout,
         actor_state_aggregation=req.actor_state_aggregation,
         actor_state_synchronization=req.actor_state_synchronization,
         actor_state_collecting=req.actor_state_collecting,
         actor_state_distributing=req.actor_state_distributing,
         actor_state_defaulted=req.LACP_STATE_OPERATIONAL_PARTNER,
         actor_state_expired=req.LACP_STATE_NOT_EXPIRED,
         partner_system_priority=req.actor_system_priority,
         partner_system=req.actor_system,
         partner_key=req.actor_key,
         partner_port_priority=req.actor_port_priority,
         partner_port=req.actor_port,
         partner_state_activity=req.actor_state_activity,
         partner_state_timeout=req.actor_state_timeout,
         partner_state_aggregation=req.actor_state_aggregation,
         partner_state_synchronization=req.actor_state_synchronization,
         partner_state_collecting=req.actor_state_collecting,
         partner_state_distributing=req.actor_state_distributing,
         partner_state_defaulted=req.actor_state_defaulted,
         partner_state_expired=req.actor_state_expired,
         collector_max_delay=0)
     self.logger.info("SW=%s PORT=%d LACP sent.",
                      dpid_to_str(datapath.id), port)
     self.logger.debug(str(res))
     return res
Пример #2
0
 def _create_lacp(self, datapath, port, req):
     """create a LACP packet."""
     actor_system = datapath.ports[datapath.ofproto.OFPP_LOCAL].hw_addr
     res = slow.lacp(
         actor_system_priority=0xffff,
         actor_system=actor_system,
         actor_key=req.actor_key,
         actor_port_priority=0xff,
         actor_port=port,
         actor_state_activity=req.LACP_STATE_PASSIVE,
         actor_state_timeout=req.actor_state_timeout,
         actor_state_aggregation=req.actor_state_aggregation,
         actor_state_synchronization=req.actor_state_synchronization,
         actor_state_collecting=req.actor_state_collecting,
         actor_state_distributing=req.actor_state_distributing,
         actor_state_defaulted=req.LACP_STATE_OPERATIONAL_PARTNER,
         actor_state_expired=req.LACP_STATE_NOT_EXPIRED,
         partner_system_priority=req.actor_system_priority,
         partner_system=req.actor_system,
         partner_key=req.actor_key,
         partner_port_priority=req.actor_port_priority,
         partner_port=req.actor_port,
         partner_state_activity=req.actor_state_activity,
         partner_state_timeout=req.actor_state_timeout,
         partner_state_aggregation=req.actor_state_aggregation,
         partner_state_synchronization=req.actor_state_synchronization,
         partner_state_collecting=req.actor_state_collecting,
         partner_state_distributing=req.actor_state_distributing,
         partner_state_defaulted=req.actor_state_defaulted,
         partner_state_expired=req.actor_state_expired,
         collector_max_delay=0)
     self.logger.info("SW=%s PORT=%d LACP sent.", dpid_to_str(datapath.id),
                      port)
     self.logger.debug(str(res))
     return res
Пример #3
0
 def test_invalid_partner_state_collecting(self):
     l = lacp(self.version,
              self.actor_system_priority,
              self.actor_system,
              self.actor_key,
              self.actor_port_priority,
              self.actor_port,
              self.actor_state_activity,
              self.actor_state_timeout,
              self.actor_state_aggregation,
              self.actor_state_synchronization,
              self.actor_state_collecting,
              self.actor_state_distributing,
              self.actor_state_defaulted,
              self.actor_state_expired,
              self.partner_system_priority,
              self.partner_system,
              self.partner_key,
              self.partner_port_priority,
              self.partner_port,
              self.partner_state_activity,
              self.partner_state_timeout,
              self.partner_state_aggregation,
              self.partner_state_synchronization,
              -1,
              self.partner_state_distributing,
              self.partner_state_defaulted,
              self.partner_state_expired,
              self.collector_max_delay)
     l.serialize()
Пример #4
0
 def _s_create_lacp_first_packet(self, datapath, port):
     actor_system = datapath.ports[datapath.ofproto.OFPP_LOCAL].hw_addr
     req = slow.lacp(
         actor_key=13,
         actor_port=port,
         actor_port_priority=0xff,
         actor_state_activity=slow.lacp.LACP_STATE_ACTIVE,
         actor_state_aggregation=slow.lacp.LACP_STATE_AGGREGATEABLE,
         actor_state_defaulted=slow.lacp.LACP_STATE_DEFAULED_PARTNER,
         actor_state_expired=slow.lacp.LACP_STATE_EXPIRED,
         actor_system=actor_system,
         actor_system_priority=0xffff,
         partner_key=1,
         partner_port=port,
         partner_port_priority=0xff,
         partner_state_activity=slow.lacp.LACP_STATE_ACTIVE,
         partner_state_timeout=slow.lacp.LACP_STATE_SHORT_TIMEOUT,
         partner_system_priority=0xffff)
     self.logger.info("SW=%s PORT=%d LACP sent.", dpid_to_str(datapath.id),
                      port)
     self.logger.debug(str(req))
     return req
Пример #5
0
def lacp_reqreply(eth_src,
                  actor_system, actor_key, actor_port,
                  actor_port_priority=0,
                  actor_state_synchronization=0,
                  actor_state_activity=0,
                  actor_state_collecting=1,
                  actor_state_distributing=1,
                  partner_system='00:00:00:00:00:00',
                  partner_key=0,
                  partner_port=0,
                  partner_system_priority=0,
                  partner_port_priority=0,
                  partner_state_defaulted=0,
                  partner_state_expired=0,
                  partner_state_timeout=0,
                  partner_state_collecting=0,
                  partner_state_distributing=0,
                  partner_state_aggregation=0,
                  partner_state_synchronization=0,
                  partner_state_activity=0):
    """Return a LACP frame.

    Args:
        eth_src (str): source Ethernet MAC address.
        actor_system (str): actor system ID (MAC address)
        actor_key (int): actor's LACP key assigned to this port.
        actor_port (int): actor port number.
        actor_state_synchronization (int): 1 if we will use this link.
        actor_state_activity (int): 1 if actively sending LACP.
        actor_state_collecting (int): 1 if receiving on this link.
        actor_state_distibuting (int): 1 if transmitting on this link.
        partner_system (str): partner system ID (MAC address)
        partner_key (int): partner's LACP key assigned to this port.
        partner_port (int): partner port number.
        partner_system_priority (int): partner's system priority.
        partner_port_priority (int): partner's port priority.
        partner_state_defaulted (int): 1 if partner reverted to defaults.
        partner_state_expired (int): 1 if partner thinks LACP expired.
        partner_state_timeout (int): 1 if partner has short timeout.
        partner_state_collecting (int): 1 if partner receiving on this link.
        partner_state_distributing (int): 1 if partner transmitting on this link.
        partner_state_aggregation (int): 1 if partner can aggregate this link.
        partner_state_synchronization (int): 1 if partner will use this link.
        partner_state_activity (int): 1 if partner actively sends LACP.
    Returns:
        ryu.lib.packet.ethernet: Ethernet packet with header.
    """
    pkt = build_pkt_header(
        None, eth_src, slow.SLOW_PROTOCOL_MULTICAST, valve_of.ether.ETH_TYPE_SLOW)
    lacp_pkt = slow.lacp(
        version=1,
        actor_system=actor_system,
        actor_port=actor_port,
        partner_system=partner_system,
        partner_port=partner_port,
        actor_key=actor_key,
        partner_key=partner_key,
        actor_system_priority=65535,
        partner_system_priority=partner_system_priority,
        actor_port_priority=actor_port_priority,
        partner_port_priority=partner_port_priority,
        actor_state_defaulted=0,
        partner_state_defaulted=partner_state_defaulted,
        actor_state_expired=0,
        partner_state_expired=partner_state_expired,
        actor_state_timeout=1,
        partner_state_timeout=partner_state_timeout,
        actor_state_collecting=actor_state_collecting,
        partner_state_collecting=partner_state_collecting,
        actor_state_distributing=actor_state_distributing,
        partner_state_distributing=partner_state_distributing,
        actor_state_aggregation=1,
        partner_state_aggregation=partner_state_aggregation,
        actor_state_synchronization=actor_state_synchronization,
        partner_state_synchronization=partner_state_synchronization,
        actor_state_activity=actor_state_activity,
        partner_state_activity=partner_state_activity)
    pkt.add_protocol(lacp_pkt)
    pkt.serialize()
    return pkt
Пример #6
0
    def _s_lacp_active_2(self, req_lacp, src, msg):
        # 将端口变为up,enabled
        # 修改timeout
        # 创建LACP报文,封装到ethernet中
        # 发送
        """packet-in process when the received packet is LACP."""
        datapath = msg.datapath
        dpid = datapath.id
        if dpid == 2:
            return
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser
        if ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            port = msg.in_port
        else:
            port = msg.match['in_port']
        self.logger.info("SW=%s PORT=%d LACP received.", dpid_to_str(dpid),
                         port)
        self.logger.debug(str(req_lacp))

        # when LACP arrived at disabled port, update the status of
        # the slave i/f to enabled, and send a event.
        if not self._get_slave_enabled(dpid, port):
            self.logger.info("SW=%s PORT=%d the slave i/f has just been up.",
                             dpid_to_str(dpid), port)
            self._set_slave_enabled(dpid, port, True)
            self.send_event_to_observers(
                EventSlaveStateChanged(datapath, port, True))

        # set the idle_timeout time using the actor state of the
        # received packet.
        if req_lacp.LACP_STATE_SHORT_TIMEOUT == \
           req_lacp.actor_state_timeout:
            idle_timeout = req_lacp.SHORT_TIMEOUT_TIME
        else:
            idle_timeout = req_lacp.LONG_TIMEOUT_TIME

        # when the timeout time has changed, update the timeout time of
        # the slave i/f and re-enter a flow entry for the packet from
        # the slave i/f with idle_timeout.
        if idle_timeout != self._get_slave_timeout(dpid, port):
            self.logger.info("SW=%s PORT=%d the timeout time has changed.",
                             dpid_to_str(dpid), port)
            self._set_slave_timeout(dpid, port, idle_timeout)
            func = self._add_flow.get(ofproto.OFP_VERSION)
            assert func
            func(src, port, idle_timeout, datapath)

        actor_system = datapath.ports[datapath.ofproto.OFPP_LOCAL].hw_addr
        if req_lacp.actor_state_synchronization == req_lacp.LACP_STATE_IN_SYNC:
            actor_state_collecting = req_lacp.LACP_STATE_COLLECTING_ENABLED
            actor_state_distributing = req_lacp.LACP_STATE_DISTRIBUTING_ENABLED
        elif req_lacp.actor_state_synchronization == req_lacp.LACP_STATE_OUT_OF_SYNC:
            actor_state_collecting = req_lacp.LACP_STATE_COLELCTING_DISABLED
            actor_state_distributing = req_lacp.LACP_STATE_DISTRIBUTING_DISABLED
        else:
            raise
        actor_state_synchronization = req_lacp.LACP_STATE_IN_SYNC
        # create a response packet.
        res = slow.lacp(  #version=LACP_VERSION_NUMBER,
            actor_system_priority=0xffff,
            actor_system=actor_system,
            actor_key=req_lacp.actor_key,
            actor_port_priority=0xff,
            actor_port=req_lacp.actor_port,
            actor_state_activity=req_lacp.LACP_STATE_ACTIVE,
            actor_state_timeout=req_lacp.actor_state_timeout,
            actor_state_aggregation=req_lacp.actor_state_aggregation,
            actor_state_defaulted=req_lacp.actor_state_defaulted,
            actor_state_expired=req_lacp.actor_state_expired,
            actor_state_collecting=actor_state_collecting,
            actor_state_distributing=actor_state_distributing,
            actor_state_synchronization=actor_state_synchronization,
            partner_system_priority=req_lacp.actor_system_priority,
            partner_system=req_lacp.actor_system,
            partner_key=req_lacp.actor_key,
            partner_port_priority=req_lacp.actor_port_priority,
            partner_port=req_lacp.actor_port,
            partner_state_activity=req_lacp.actor_state_activity,
            partner_state_timeout=req_lacp.actor_state_timeout,
            partner_state_aggregation=req_lacp.actor_state_aggregation,
            partner_state_synchronization=req_lacp.actor_state_synchronization,
            partner_state_collecting=req_lacp.actor_state_collecting,
            partner_state_distributing=req_lacp.actor_state_distributing,
            partner_state_defaulted=req_lacp.actor_state_defaulted,
            partner_state_expired=req_lacp.actor_state_expired,
            collector_max_delay=0)

        # create a response packet.
        res_pkt = self._s_create_eth_packet(datapath, port, res)

        # packet-out the response packet.
        # out_port = port
        out_port = ofproto.OFPP_IN_PORT
        actions = [parser.OFPActionOutput(out_port)]
        # out = datapath.ofproto_parser.OFPPacketOut(
        #     datapath=datapath, buffer_id=ofproto.OFP_NO_BUFFER,
        #     data=res_pkt.data, in_port=port, actions=actions)
        out = parser.OFPPacketOut(datapath=datapath,
                                  buffer_id=ofproto.OFP_NO_BUFFER,
                                  data=res_pkt.data,
                                  in_port=port,
                                  actions=actions)
        datapath.send_msg(out)
        if req_lacp.actor_state_distributing == req_lacp.LACP_STATE_DISTRIBUTING_ENABLED:
            self._s_is_distributing = True
Пример #7
0
    def setUp(self):
        self.subtype = SLOW_SUBTYPE_LACP
        self.version = lacp.LACP_VERSION_NUMBER
        self.actor_tag = lacp.LACP_TLV_TYPE_ACTOR
        self.actor_length = 20
        self.actor_system_priority = 65534
        self.actor_system = '00:07:0d:af:f4:54'
        self.actor_key = 1
        self.actor_port_priority = 65535
        self.actor_port = 1
        self.actor_state_activity = lacp.LACP_STATE_ACTIVE
        self.actor_state_timeout = lacp.LACP_STATE_LONG_TIMEOUT
        self.actor_state_aggregation = lacp.LACP_STATE_AGGREGATEABLE
        self.actor_state_synchronization = lacp.LACP_STATE_IN_SYNC
        self.actor_state_collecting = lacp.LACP_STATE_COLLECTING_ENABLED
        self.actor_state_distributing = lacp.LACP_STATE_DISTRIBUTING_ENABLED
        self.actor_state_defaulted = lacp.LACP_STATE_OPERATIONAL_PARTNER
        self.actor_state_expired = lacp.LACP_STATE_EXPIRED
        self.actor_state = (
            (self.actor_state_activity << 0) |
            (self.actor_state_timeout << 1) |
            (self.actor_state_aggregation << 2) |
            (self.actor_state_synchronization << 3) |
            (self.actor_state_collecting << 4) |
            (self.actor_state_distributing << 5) |
            (self.actor_state_defaulted << 6) |
            (self.actor_state_expired << 7))
        self.partner_tag = lacp.LACP_TLV_TYPE_PARTNER
        self.partner_length = 20
        self.partner_system_priority = 0
        self.partner_system = '00:00:00:00:00:00'
        self.partner_key = 0
        self.partner_port_priority = 0
        self.partner_port = 0
        self.partner_state_activity = 0
        self.partner_state_timeout = lacp.LACP_STATE_SHORT_TIMEOUT
        self.partner_state_aggregation = 0
        self.partner_state_synchronization = 0
        self.partner_state_collecting = 0
        self.partner_state_distributing = 0
        self.partner_state_defaulted = 0
        self.partner_state_expired = 0
        self.partner_state = (
            (self.partner_state_activity << 0) |
            (self.partner_state_timeout << 1) |
            (self.partner_state_aggregation << 2) |
            (self.partner_state_synchronization << 3) |
            (self.partner_state_collecting << 4) |
            (self.partner_state_distributing << 5) |
            (self.partner_state_defaulted << 6) |
            (self.partner_state_expired << 7))
        self.collector_tag = lacp.LACP_TLV_TYPE_COLLECTOR
        self.collector_length = 16
        self.collector_max_delay = 0
        self.terminator_tag = lacp.LACP_TLV_TYPE_TERMINATOR
        self.terminator_length = 0

        self.head_fmt = lacp._HLEN_PACK_STR
        self.head_len = lacp._HLEN_PACK_LEN
        self.act_fmt = lacp._ACTPRT_INFO_PACK_STR
        self.act_len = lacp._ACTPRT_INFO_PACK_LEN
        self.prt_fmt = lacp._ACTPRT_INFO_PACK_STR
        self.prt_len = lacp._ACTPRT_INFO_PACK_LEN
        self.col_fmt = lacp._COL_INFO_PACK_STR
        self.col_len = lacp._COL_INFO_PACK_LEN
        self.trm_fmt = lacp._TRM_PACK_STR
        self.trm_len = lacp._TRM_PACK_LEN
        self.length = lacp._ALL_PACK_LEN

        self.head_buf = pack(self.head_fmt,
                             self.subtype,
                             self.version)
        self.act_buf = pack(self.act_fmt,
                            self.actor_tag,
                            self.actor_length,
                            self.actor_system_priority,
                            addrconv.mac.text_to_bin(self.actor_system),
                            self.actor_key,
                            self.actor_port_priority,
                            self.actor_port,
                            self.actor_state)
        self.prt_buf = pack(self.prt_fmt,
                            self.partner_tag,
                            self.partner_length,
                            self.partner_system_priority,
                            addrconv.mac.text_to_bin(self.partner_system),
                            self.partner_key,
                            self.partner_port_priority,
                            self.partner_port,
                            self.partner_state)
        self.col_buf = pack(self.col_fmt,
                            self.collector_tag,
                            self.collector_length,
                            self.collector_max_delay)
        self.trm_buf = pack(self.trm_fmt,
                            self.terminator_tag,
                            self.terminator_length)

        self.buf = self.head_buf + self.act_buf + self.prt_buf + \
            self.col_buf + self.trm_buf

        self.l = lacp(self.version,
                      self.actor_system_priority,
                      self.actor_system,
                      self.actor_key,
                      self.actor_port_priority,
                      self.actor_port,
                      self.actor_state_activity,
                      self.actor_state_timeout,
                      self.actor_state_aggregation,
                      self.actor_state_synchronization,
                      self.actor_state_collecting,
                      self.actor_state_distributing,
                      self.actor_state_defaulted,
                      self.actor_state_expired,
                      self.partner_system_priority,
                      self.partner_system,
                      self.partner_key,
                      self.partner_port_priority,
                      self.partner_port,
                      self.partner_state_activity,
                      self.partner_state_timeout,
                      self.partner_state_aggregation,
                      self.partner_state_synchronization,
                      self.partner_state_collecting,
                      self.partner_state_distributing,
                      self.partner_state_defaulted,
                      self.partner_state_expired,
                      self.collector_max_delay)
Пример #8
0
def lacp_reqreply(eth_src,
                  actor_system, actor_key, actor_port,
                  actor_state_synchronization=0,
                  actor_state_activity=0,
                  partner_system='00:00:00:00:00:00',
                  partner_key=0,
                  partner_port=0,
                  partner_system_priority=0,
                  partner_port_priority=0,
                  partner_state_defaulted=0,
                  partner_state_expired=0,
                  partner_state_timeout=0,
                  partner_state_collecting=0,
                  partner_state_distributing=0,
                  partner_state_aggregation=0,
                  partner_state_synchronization=0,
                  partner_state_activity=0):
    """Return a LACP frame.

    Args:
        eth_src (str): source Ethernet MAC address.
        actor_system (str): actor system ID (MAC address)
        actor_key (int): actor's LACP key assigned to this port.
        actor_port (int): actor port number.
        actor_state_synchronization (int): 1 if we will use this link.
        actor_state_activity (int): 1 if actively sending LACP.
        partner_system (str): partner system ID (MAC address)
        partner_key (int): partner's LACP key assigned to this port.
        partner_port (int): partner port number.
        partner_system_priority (int): partner's system priority.
        partner_port_priority (int): partner's port priority.
        partner_state_defaulted (int): 1 if partner reverted to defaults.
        partner_state_expired (int): 1 if partner thinks LACP expired.
        partner_state_timeout (int): 1 if partner has short timeout.
        partner_state_collecting (int): 1 if partner receiving on this link.
        partner_state_distributing (int): 1 if partner transmitting on this link.
        partner_state_aggregation (int): 1 if partner can aggregate this link.
        partner_state_synchronization (int): 1 if partner will use this link.
        partner_state_activity (int): 1 if partner actively sends LACP.
    Returns:
        ryu.lib.packet.ethernet: Ethernet packet with header.
    """
    pkt = build_pkt_header(
        None, eth_src, slow.SLOW_PROTOCOL_MULTICAST, valve_of.ether.ETH_TYPE_SLOW)
    lacp_pkt = slow.lacp(
        version=1,
        actor_system=actor_system,
        actor_port=actor_port,
        partner_system=partner_system,
        partner_port=partner_port,
        actor_key=actor_key,
        partner_key=partner_key,
        actor_system_priority=65535,
        partner_system_priority=partner_system_priority,
        actor_port_priority=255,
        partner_port_priority=partner_port_priority,
        actor_state_defaulted=0,
        partner_state_defaulted=partner_state_defaulted,
        actor_state_expired=0,
        partner_state_expired=partner_state_expired,
        actor_state_timeout=1,
        partner_state_timeout=partner_state_timeout,
        actor_state_collecting=1,
        partner_state_collecting=partner_state_collecting,
        actor_state_distributing=1,
        partner_state_distributing=partner_state_distributing,
        actor_state_aggregation=1,
        partner_state_aggregation=partner_state_aggregation,
        actor_state_synchronization=actor_state_synchronization,
        partner_state_synchronization=partner_state_synchronization,
        actor_state_activity=actor_state_activity,
        partner_state_activity=partner_state_activity)
    pkt.add_protocol(lacp_pkt)
    pkt.serialize()
    return pkt