コード例 #1
0
 def add_meter(
     datapath,
     meter_id: int,
     rate: int,
     burst_size: int,
     retries=3,
 ):
     LOG.debug(
         "adding meter_id: %d rate: %d burst_size: %d",
         meter_id,
         rate,
         burst_size,
     )
     bands = []
     ofproto, parser = datapath.ofproto, datapath.ofproto_parser
     dropband = parser.OFPMeterBandDrop(rate=rate, burst_size=burst_size)
     bands.append(dropband)
     mod = parser.OFPMeterMod(
         datapath=datapath,
         command=ofproto.OFPMC_ADD,
         flags=ofproto.OFPMF_KBPS,
         meter_id=meter_id,
         bands=bands,
     )
     messages.send_msg(datapath, mod, retries)
コード例 #2
0
ファイル: testing.py プロジェクト: jaredmullane/docu_2
 def ryu_query_lookup(self, ryu, stats_queue):
     """
     Send a FlowStatsRequest message to the datapath
     """
     self._stats_queue = stats_queue
     parser = self._datapath.ofproto_parser
     match = parser.OFPMatch(**ryu["match"].ryu_match) \
         if ryu["match"] is not None else None
     if "cookie" not in ryu:
         # If cookie is not set in the parameter, then do not match on
         # cookie.
         req = parser.OFPFlowStatsRequest(self._datapath,
                                          table_id=ryu["table_id"],
                                          match=match)
     else:
         req = parser.OFPFlowStatsRequest(
             self._datapath,
             table_id=ryu["table_id"],
             match=match,
             cookie=ryu["cookie"],
             cookie_mask=flows.OVS_COOKIE_MATCH_ALL)
     try:
         messages.send_msg(self._datapath, req)
     except MagmaOFError as e:
         self.logger.warning("Couldn't poll datapath stats: %s", e)
コード例 #3
0
ファイル: flows.py プロジェクト: ssanadhya/magma
def add_output_flow(
    datapath,
    table,
    match,
    actions=None,
    instructions=None,
    priority=MINIMUM_PRIORITY,
    retries=3,
    cookie=0x0,
    idle_timeout=0,
    hard_timeout=0,
    output_port=None,
    output_reg=None,
    copy_table=None,
    max_len=None,
):
    """
    Add a flow to a table that sends the packet to the specified port

    Args:
        datapath (ryu.controller.controller.Datapath):
            Datapath to push the flow to
        table (int): Table number to apply the flow to
        match (MagmaMatch): The match for the flow
        actions ([OFPAction]):
            List of actions for the flow.
        instructions ([OFPInstruction]):
            List of instructions for the flow. This will default to a
            single OFPInstructionsActions to apply `actions`.
            Ignored if `actions` is set.
        priority (int): Flow priority
        retries (int): Number of times to retry pushing the flow on failure
        cookie (hex): cookie value for the flow
        idle_timeout (int): idle timeout for the flow
        hard_timeout (int): hard timeout for the flow
        output_port (int): the port to send the packet
        copy_table (int): optional table to send the packet to
        max_len (int): Max length to send to controller

    Raises:
        MagmaOFError: if the flow can't be added
        Exception: If the actions contain NXActionResubmitTable.
    """
    mod = get_add_output_flow_msg(
        datapath,
        table,
        match,
        actions=actions,
        instructions=instructions,
        priority=priority,
        cookie=cookie,
        idle_timeout=idle_timeout,
        hard_timeout=hard_timeout,
        copy_table=copy_table,
        output_port=output_port,
        output_reg=output_reg,
        max_len=max_len,
    )
    logger.debug('flowmod: %s (table %s)', mod, table)
    messages.send_msg(datapath, mod, retries)
コード例 #4
0
 def del_all_meters(datapath, retries=3):
     LOG.debug("deleting all meters")
     ofproto, parser = datapath.ofproto, datapath.ofproto_parser
     mod = parser.OFPMeterMod(datapath=datapath,
                              command=ofproto.OFPMC_DELETE,
                              meter_id=ofproto.OFPM_ALL)
     messages.send_msg(datapath, mod, retries)
コード例 #5
0
ファイル: flows.py プロジェクト: florinasp/magma-1
def delete_flow(datapath,
                table,
                match,
                actions=None,
                instructions=None,
                retries=3,
                **kwargs):
    """
    Delete a flow from the given table

    Args:
        datapath (ryu.controller.controller.Datapath): Datapath to configure.
        table (int): table to delete the flow from
        match (MagmaMatch): match for the flow
        actions ([OFPAction]):
            Actions for the flow. Ignored if `instructions` is set.
        instructions ([OFPInstruction]):
            Instructions for the flow. This will default to a single
            OFPInstructionsActions for `actions`.
        retries (int): retry attempts on failure.

    Raises:
        MagmaOFError: if the flow can't be deleted
    """
    msg = get_delete_flow_msg(datapath, table, match, actions, instructions,
                              **kwargs)
    logger.debug('flowmod: %s (table %s)', msg, table)
    messages.send_msg(datapath, msg, retries=retries)
コード例 #6
0
 def del_meter(datapath, meter_id: int, retries=3):
     LOG.debug("deleting meter_id: %d", meter_id)
     ofproto, parser = datapath.ofproto, datapath.ofproto_parser
     mod = parser.OFPMeterMod(datapath=datapath,
                              command=ofproto.OFPMC_DELETE,
                              meter_id=meter_id)
     messages.send_msg(datapath, mod, retries)
コード例 #7
0
def add_flow(datapath, table, match, actions=None, instructions=None,
             priority=MINIMUM_PRIORITY, retries=3, cookie=0x0, idle_timeout=0,
             hard_timeout=0, goto_table=None):
    """
    Add a flow based on provided args.

    Args:
        datapath (ryu.controller.controller.Datapath):
            Datapath to push the flow to
        table (int): Table number to apply the flow to
        match (MagmaMatch): The match for the flow
        actions ([OFPAction]):
            List of actions for the flow.
        instructions ([OFPInstruction]):
            List of instructions for the flow. This will default to a
            single OFPInstructionsActions to apply `actions`.
            Ignored if `actions` is set.
        priority (int): Flow priority
        retries (int): Number of times to retry pushing the flow on failure
        cookie (hex): cookie value for the flow
        idle_timeout (int): idle timeout for the flow
        hard_timeout (int): hard timeout for the flow

    Raises:
        MagmaOFError: if the flow can't be added
        Exception: If the actions contain NXActionResubmitTable.
            Or if the flow is resubmitted to the next service and the actions
            contain an action that loads the scratch register. The scratch
            register is reset on table resubmit so any load has no effect.
    """
    ofproto, parser = datapath.ofproto, datapath.ofproto_parser

    if actions is None:
        actions = []
    # As 4G GTP tunnel, Register value is not used.
    # if use for default flow, 4G traffic is dropping.
    if ((goto_table != CLASSIFIER_NEXT_TABLE_NUM) and
                     (goto_table != CLASSIFIER_INTERNAL_SAMPLING_FWD_TABLE_NUM)):
        reset_scratch_reg_actions = [
             parser.NXActionRegLoad2(dst=reg, value=REG_ZERO_VAL)
             for reg in SCRATCH_REGS]
        actions = actions + reset_scratch_reg_actions

    inst = __get_instructions_for_actions(ofproto, parser,
                                          actions, instructions)

    # For 5G GTP tunnel, goto_table is used for downlink and uplink
    if goto_table:
        inst.append(parser.OFPInstructionGotoTable(goto_table))

    ryu_match = parser.OFPMatch(**match.ryu_match)

    mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
                            match=ryu_match, instructions=inst,
                            table_id=table, cookie=cookie,
                            idle_timeout=idle_timeout,
                            hard_timeout=hard_timeout)

    logger.debug('flowmod: %s (table %s)', mod, table)
    messages.send_msg(datapath, mod, retries)
コード例 #8
0
def send_stats_request(datapath,
                       tbl_num,
                       cookie: hex = 0,
                       cookie_mask: hex = 0,
                       retries: int = 3):
    """
    Send a stats request msg 
    Args:
        datapath (ryu.controller.controller.Datapath):
            Datapath to query from
        table (int): Table number to query for
        cookie (hex): cookie value for the request
        cookie_mask(hex): cookie mask for the request
    """
    ofproto, parser = datapath.ofproto, datapath.ofproto_parser
    req = parser.OFPFlowStatsRequest(
        datapath,
        table_id=tbl_num,
        out_group=ofproto.OFPG_ANY,
        out_port=ofproto.OFPP_ANY,
        cookie=cookie,
        cookie_mask=cookie_mask,
    )
    logger.debug('flowmod: %s (table %d)', req, tbl_num)
    messages.send_msg(datapath, req, retries)
コード例 #9
0
ファイル: flows.py プロジェクト: wlm328cs/magma
def delete_flow(datapath, table, match, actions=None, instructions=None,
                retries=3, **kwargs):
    """
    Delete a flow from the given table

    Args:
        datapath (ryu.controller.controller.Datapath): Datapath to configure.
        table (int): table to delete the flow from
        match (MagmaMatch): match for the flow
        actions ([OFPAction]):
            Actions for the flow. Ignored if `instructions` is set.
        instructions ([OFPInstruction]):
            Instructions for the flow. This will default to a single
            OFPInstructionsActions for `actions`.
        retries (int): retry attempts on failure.

    Raises:
        MagmaOFError: if the flow can't be deleted
    """
    ofproto, parser = datapath.ofproto, datapath.ofproto_parser
    inst = __get_instructions_for_actions(ofproto, parser,
                                          actions, instructions)
    ryu_match = parser.OFPMatch(**match.ryu_match)

    mod = parser.OFPFlowMod(datapath=datapath, command=ofproto.OFPFC_DELETE,
                            match=ryu_match, instructions=inst,
                            table_id=table, out_group=ofproto.OFPG_ANY,
                            out_port=ofproto.OFPP_ANY,
                            **kwargs)
    logger.debug('flowmod: %s (table %s)', mod, table)
    messages.send_msg(datapath, mod, retries=retries)
コード例 #10
0
 def dump_all_meters(datapath, retries=3):
     LOG.debug("dumping all meters")
     ofproto, parser = datapath.ofproto, datapath.ofproto_parser
     stat = parser.OFPMeterConfigStatsRequest(
         datapath=datapath,
         meter_id=ofproto.OFPM_ALL,
     )
     messages.send_msg(datapath, stat, retries)
コード例 #11
0
def add_resubmit_next_service_flow(datapath,
                                   table,
                                   match,
                                   actions=None,
                                   instructions=None,
                                   priority=MINIMUM_PRIORITY,
                                   retries=3,
                                   cookie=0x0,
                                   idle_timeout=0,
                                   hard_timeout=0,
                                   copy_table=None,
                                   reset_default_register: bool = True,
                                   resubmit_table=None):
    """
    Add a flow to a table that resubmits to another service.
    All scratch registers will be reset before resubmitting.

    Args:
        datapath (ryu.controller.controller.Datapath):
            Datapath to push the flow to
        table (int): Table number to apply the flow to
        match (MagmaMatch): The match for the flow
        actions ([OFPAction]):
            List of actions for the flow.
        instructions ([OFPInstruction]):
            List of instructions for the flow. This will default to a
            single OFPInstructionsActions to apply `actions`.
            Ignored if `actions` is set.
        priority (int): Flow priority
        retries (int): Number of times to retry pushing the flow on failure
        cookie (hex): cookie value for the flow
        idle_timeout (int): idle timeout for the flow
        hard_timeout (int): hard timeout for the flow
        resubmit_table (int): Table number of the next service to
            forward traffic to.

    Raises:
        MagmaOFError: if the flow can't be added
        Exception: If the actions contain NXActionResubmitTable.
            Or if the flow is resubmitted to the next service and the actions
            contain an action that loads the scratch register. The scratch
            register is reset on table resubmit so any load has no effect.
    """
    mod = get_add_resubmit_next_service_flow_msg(
        datapath,
        table,
        match,
        actions=actions,
        instructions=instructions,
        priority=priority,
        cookie=cookie,
        idle_timeout=idle_timeout,
        hard_timeout=hard_timeout,
        copy_table=copy_table,
        reset_default_register=reset_default_register,
        resubmit_table=resubmit_table)
    logger.debug('flowmod: %s (table %s)', mod, table)
    messages.send_msg(datapath, mod, retries)
コード例 #12
0
def add_drop_flow(datapath,
                  table,
                  match,
                  actions=None,
                  instructions=None,
                  priority=MINIMUM_PRIORITY,
                  retries=3,
                  cookie=0x0,
                  idle_timeout=0,
                  hard_timeout=0,
                  install_trace_flow=False):
    """
    Add a flow to a table that drops the packet

    Args:
        datapath (ryu.controller.controller.Datapath):
            Datapath to push the flow to
        table (int): Table number to apply the flow to
        match (MagmaMatch): The match for the flow
        actions ([OFPAction]):
            List of actions for the flow.
        instructions ([OFPInstruction]):
            List of instructions for the flow. This will default to a
            single OFPInstructionsActions to apply `actions`.
            Ignored if `actions` is set.
        priority (int): Flow priority
        retries (int): Number of times to retry pushing the flow on failure
        cookie (hex): cookie value for the flow
        idle_timeout (int): idle timeout for the flow
        hard_timeout (int): hard timeout for the flow
        install_trace_flow (bool): whether to install the packet-tracing flow

    Raises:
        MagmaOFError: if the flow can't be added
        Exception: If the actions contain NXActionResubmitTable.
    """
    mod = get_add_drop_flow_msg(datapath,
                                table,
                                match,
                                actions=actions,
                                instructions=instructions,
                                priority=priority,
                                cookie=cookie,
                                idle_timeout=idle_timeout,
                                hard_timeout=hard_timeout)
    logger.debug('flowmod: %s (table %s)', mod, table)
    messages.send_msg(datapath, mod, retries)

    if install_trace_flow:
        add_trace_packet_output_flow(datapath,
                                     table,
                                     match,
                                     instructions=instructions,
                                     priority=priority + 1,
                                     retries=retries,
                                     cookie=cookie,
                                     idle_timeout=idle_timeout,
                                     hard_timeout=hard_timeout)
コード例 #13
0
ファイル: testing.py プロジェクト: jaredmullane/docu_2
    def table_stats_lookup(self, queue):
        """
        Send a TableStatsRequest message to the datapath
        """
        self._agr_stats_queue = queue

        parser = self._datapath.ofproto_parser
        req = parser.OFPTableStatsRequest(self._datapath, 0)
        try:
            messages.send_msg(self._datapath, req)
        except MagmaOFError as e:
            self.logger.warning("Couldn't poll datapath stats: %s", e)
コード例 #14
0
ファイル: flows.py プロジェクト: florinasp/magma-1
def set_barrier(datapath):
    """
    Sends a barrier to the specified datapath to ensure all previous flows
    are pushed.

    Args:
        datapath (ryu.controller.controller.Datapath): Datapath to message.

    Raises:
        MagmaOFError: if barrier request fails
    """
    parser = datapath.ofproto_parser
    messages.send_msg(datapath, parser.OFPBarrierRequest(datapath))
コード例 #15
0
def add_trace_packet_output_flow(datapath,
                                 table,
                                 match,
                                 instructions=None,
                                 priority=MINIMUM_PRIORITY,
                                 retries=3,
                                 cookie=0x0,
                                 idle_timeout=0,
                                 hard_timeout=0):
    """
    Add a flow to a table that sends the packet to the user-space.
    This is used to trace packets and send the test-packet to the user space.
    This flow should be installed to send the packet to the user-space instead
    of dropping it if the packet is a test-packet.
    PacketTracingController will handle the rest.

    Args:
        datapath (ryu.controller.controller.Datapath):
            Datapath to push the flow to
        table (int): Table number to apply the flow to
        match (MagmaMatch): The match for the flow excluding trace bit match
        instructions ([OFPInstruction]):
            List of instructions for the flow. This will default to a
            single OFPInstructionsActions to apply `actions`.
            Ignored if `actions` is set.
        priority (int): Flow priority
        retries (int): Number of times to retry pushing the flow on failure
        cookie (hex): cookie value for the flow
        idle_timeout (int): idle timeout for the flow
        hard_timeout (int): hard timeout for the flow

    Raises:
        MagmaOFError: if the flow can't be added
        Exception: If the actions contain NXActionResubmitTable.
    """
    trace_match = copy(match)
    trace_match.update({TEST_PACKET_REG: TestPacket.ON.value})

    ofproto = datapath.ofproto
    mod = get_add_output_flow_msg(datapath,
                                  table,
                                  trace_match,
                                  actions=[],
                                  instructions=instructions,
                                  priority=priority,
                                  cookie=cookie,
                                  idle_timeout=idle_timeout,
                                  hard_timeout=hard_timeout,
                                  output_port=ofproto.OFPP_CONTROLLER,
                                  max_len=ofproto.OFPCML_NO_BUFFER)
    messages.send_msg(datapath, mod, retries)
コード例 #16
0
 def _poll_stats(self, datapath):
     """
     Send a FlowStatsRequest message to the datapath
     """
     ofproto, parser = datapath.ofproto, datapath.ofproto_parser
     req = parser.OFPFlowStatsRequest(
         datapath,
         table_id=self.tbl_num,
         out_group=ofproto.OFPG_ANY,
         out_port=ofproto.OFPP_ANY,
     )
     try:
         messages.send_msg(datapath, req)
     except MagmaOFError as e:
         self.logger.warning("Couldn't poll datapath stats: %s", e)
コード例 #17
0
ファイル: testing.py プロジェクト: robcee/magma
 def ryu_query_lookup(self, ryu, stats_queue):
     """
     Send a FlowStatsRequest message to the datapath
     """
     self._stats_queue = stats_queue
     parser = self._datapath.ofproto_parser
     match = parser.OFPMatch(**ryu["match"].ryu_match) \
         if ryu["match"] is not None else None
     req = parser.OFPFlowStatsRequest(self._datapath,
                                      table_id=ryu["table_id"],
                                      match=match)
     try:
         messages.send_msg(self._datapath, req)
     except MagmaOFError as e:
         self.logger.warning("Couldn't poll datapath stats: %s", e)
コード例 #18
0
 def dump_meter_features(datapath, retries=3):
     LOG.debug("dumping meter features")
     parser = datapath.ofproto_parser
     stat = parser.OFPMeterFeaturesStatsRequest(datapath=datapath)
     messages.send_msg(datapath, stat, retries)
コード例 #19
0
 def _set_classifier_controller_id(self):
     req = ofproto_v1_0_parser.NXTSetControllerId(
         self._datapath,
         controller_id=self.config.classifier_controller_id,
     )
     messages.send_msg(self._datapath, req)