ONOS+P4 Tutorial: Exercise 1

ONOS+P4 Tutorial: Exercise 1

纯翻译记录

The goal of this exercise is to introduce P4 and P4Runtime support in ONOS, along with the tools to practically experiment with it. In this exercise we will see how the ONOS “pipeconf” mechanism allow one to re-use existing ONOS apps to provide basic forwarding capabilities in a pipeline-agnostic manner, i.e. independently of the P4 program.
本练习的目标是在ONOS中引入P4和P4运行时支持,以及实际使用它的工具。
在本练习中,我们将看到ONOS的“pipeconf”机制如何允许您以管道不可知的方式(即独立于P4程序)重新使用现有的ONOS应用程序来提供基本的转发功能。

To run this exercise you will need multiple terminal windows (or tabs) to operate with the CLI of Mininet, ONOS, and BMv2. We use the following convention to distinguish between commands of different CLIs:
要运行此练习,您需要使用多个终端窗口(或选项卡)才能使用Mininet,
ONOS和BMv2的CLI进行操作。我们使用以下约定来区分不同CLI的命令:

  • Commands starting with $ are intended to be executed in the Ubuntu terminal prompt;
  • onos> for commands in the ONOS CLI;
  • mininet> for the Mininet CLI;
  • RuntimeCmd: for the BMv2 CLI.
  • $开头的命令旨在在Ubuntu终端提示符中执行;
  • onos>用于ONOS CLI中的命令;
  • mininet>Mininet CLI的;
  • RuntimeCmd:用于BMv2 CLI。

Exercise steps

  1. On terminal window 1, start ONOS with a small subset of the apps by executing the following command:
    在终端窗口1上,通过执行以下命令,用一小部分应用程序启动ONOS:

    $ cd $ONOS_ROOT
    $ ONOS_APPS=proxyarp,hostprovider,lldpprovider ok clean
    

    The $ONOS_ROOT environment variable points to the root ONOS directory. The ok command is an alias to run ONOS locally in your dev machine. Please note that if this the first time you run ONOS on this machine, or if you haven’t built ONOS before, it can take some time (5-10 minutes depending on your Internet speed).
    $ ONOS_ROOT环境变量指向根ONOS目录。
    ok命令是在您的开发机器中本地运行ONOS的别名。
    请注意,如果这是第一次在此计算机上运行ONOS,或者之前未构建ONOS,则可能需要一些时间(5-10分钟,具体取决于您的Internet速度)。

    Once ONOS has started you should see log messages being print on the screen
    ONOS启动后,您应该会在屏幕上看到正在打印的日志消息。

  2. On terminal window 2, activate the BMv2 driver and tutorial pipeconf via the ONOS CLI.
    在终端窗口2上,通过ONOS CLI激活BMv2驱动程序和教程pipeconf

    1. Use the following command to access the ONOS CLI:
      使用以下命令访问ONOS CLI

      $ onos localhost
      

      You should now see the ONOS CLI command prompt. For a list of possible commands that you can use here, type:
      您现在应该看到ONOS CLI命令提示符。有关可在此处使用的可能命令的列表,请键入:

      onos> help onos
      
    2. Enter the following command to activate the BMv2 driver:
      输入以下命令以激活BMv2驱动程序

      onos> app activate org.onosproject.drivers.bmv2
      

      You should see the following message on the ONOS log:
      您应该在ONOS日志上看到以下消息:

      Application org.onosproject.drivers.bmv2 has been activated
      
    3. Enter the following command to activate the pipeconf:
      输入以下命令以激活pipeconf

      onos> app activate org.onosproject.p4tutorial.pipeconf
      

      You should see the following messages on the log:
      您应该在日志中看到以下消息:

      New pipeconf registered: p4-tutorial-pipeconf
      Application org.onosproject.p4tutorial.pipeconf has been activated
      

      Please note the specific name used for this pipeconf p4-tutorial-pipeconf. We will later use this name to tell ONOS to deploy that specific P4 program to the switches.
      请注意这个pipeconfp4-tutorial-pipeconf的具体名称。
      我们稍后将使用此名称告诉ONOS将特定的P4程序部署到交换机。

    4. To verify that you have activated all the required apps, run the following command:
      要验证您是否已激活所有必需的应用程序,请运行以下命令:

      onos> apps -a -s
      

      Make sure you see the following list of apps displayed:
      确保您看到以下显示的应用列表:

      org.onosproject.generaldeviceprovider ... General Device Provider
      org.onosproject.drivers               ... Default Drivers
      org.onosproject.proxyarp              ... Proxy ARP/NDP
      org.onosproject.lldpprovider          ... LLDP Link Provider
      org.onosproject.protocols.grpc        ... gRPC Protocol Subsystem
      org.onosproject.protocols.p4runtime   ... P4Runtime Protocol Subsystem
      org.onosproject.p4runtime             ... P4Runtime Provider
      org.onosproject.drivers.p4runtime     ... P4Runtime Drivers
      org.onosproject.hostprovider          ... Host Location Provider
      org.onosproject.drivers.bmv2          ... BMv2 Drivers
      org.onosproject.p4tutorial.pipeconf   ... P4 Tutorial Pipeconf
      
    5. (optional) Change flow rule polling interval. Run the following
      command in the ONOS CLI:
      (可选)更改流规则轮询间隔。 在ONOS CLI中运行以下命令:

      onos> cfg set org.onosproject.net.flow.impl.FlowRuleManager fallbackFlowPollFrequency 5
      

      This command tells ONOS to check the state of flow rules on switches every 5 seconds (default is 30). This is used to obtain more often flow rules stats such as byte/packet counters. It helps also resolving more quickly issues where some flow rules are installed in the ONOS store but not on the device (which can often happen when emulating a large number of devices in the same VM).
      此命令告诉ONOS每隔5秒检查一次交换机上的流规则状态(默认值为30)。
      这用于获取更频繁的流规则统计信息,例如字节/数据包计数器。
      它还有助于更快地解决在ONOS存储中安装某些流规则但在设备上没有安装的问题(在同一VM中模拟大量设备时通常会发生这种情况)。

  3. On terminal window 3, run Mininet to set up a topology of BMv2 devices.
    在终端窗口3上,运行Mininet以设置BMv2设备的拓扑

    1. To run Mininet, use the following command:
      运行Mininet,请使用以下命令:

      $ sudo -E mn --custom $BMV2_MN_PY --switch onosbmv2,pipeconf=p4-tutorial-pipeconf --controller remote,ip=127.0.0.1
      

      The --custom argument tells Mininet to use the bmv2.py custom script to execute the BMv2 switch. The environment variable $BMV2_MN_PY points to the exact location of the script (you can use the command echo $BMV2_MN_PY to find out the location).
      --custom参数告诉Mininet使用bmv2.py自定义脚本来执行BMv2开关。
      环境变量$ BMV2_MN_PY指向脚本的确切位置(您可以使用命令echo $ BMV2_MN_PY来查找位置)。

      The --switch argument specifies the kind of switch instance we want to run inside Mininet. In this case we are running a version of BMv2 that also produces some configuration files used by ONOS to discover the device (see steps below), hence the name onosbmv2. The pipeconf sub-argument is used to tell ONOS which pipeconf to deploy on all devices.
      --switch参数指定我们想在Mininet中运行的交换机实例的类型。
      在这种情况下,我们运行的是BMv2版本,它还会生成一些ONOS用来发现设备的配置文件(参见下面的步骤),因此名称为onosbmv2pipeconf子参数用于告诉ONOS在所有设备上部署哪个pipeconf。

      The --controller argument specifies the address of the controller, ONOS in this case, which is running on the same machine where we are executing Mininet.
      --controller参数指定控制器的地址,在这种情况下是ONOS,它在我们执行Mininet的同一台机器上运行。

    2. A set of files are generated in the /tmp folder as part of this startup process, to view them (on a separate terminal window):
      作为此启动过程的一部分,在/ tmp文件夹中生成一组文件,以查看它们(在单独的终端窗口上):

      $ ls /tmp
      
    3. You will find ONOS netcfg JSON files in this folder for each BMv2 switch, open this file up, for example:
      您将在每个BMv2交换机中找到此文件夹中的ONOS netcfg JSON文件,打开此文件,例如:

      $ cat /tmp/bmv2-s1-netcfg.json
      

      It contains the configuration for (1) the gRPC server and port used by the BMv2 switch process for the P4Runtime service, (2) the ID of pipeconf to deploy on the device, (3) switch ports details, and other driver-specific information.
      它包含以下配置:
      (1)BMR2交换机进程为P4Runtime服务使用的gRPC服务器和端口,
      (2)要在设备上部署的pipeconf的ID,
      (3)交换机端口详细信息以及其他特定于驱动程序的信息。

      This file is pushed to ONOS automatically by Mininet when executing the switch instance. If everything went as expected, you should see the ONOS log populating with messages like:
      执行交换机实例时,Mininet会自动将此文件推送到ONOS
      如果一切按预期进行,您应该看到ONOS日志填充了以下消息:

      Connecting to device device:bmv2:s1 with driver bmv2
      [...]
      Setting pipeline config for device:bmv2:s1 to p4-tutorial-pipeconf...
      [...]
      Device device:bmv2:s1 connected
      [...]
      
    4. Check the BMv2 switch instance log:
      检查BMv2交换机实例日志

      $ less /tmp/bmv2-s1-log
      

      By scrolling the BMv2 log, you should see all P4Runtime messages received by the switch. These messages are sent by ONOS and are used to install table entries and to read counters. You should also see many PACKET_IN and PACKET_OUT messages corresponding to packet-in/out processed by the switch and used for LLDP-based link discovery.
      通过滚动BMv2日志,您应该看到交换机收到的所有P4Runtime消息。
      这些消息由ONOS发送,用于安装表条目和读取计数器。您还应该看到许多与交换机处理的数据包输入/输出相对应的PACKET_INPACKET_OUT消息,并用于基于LLDP的链路发现。

      Table entry messages are generated by ONOS according to the flow rules generated by each app and based on the P4Info associated with the p4-tutorial-pipeconf.
      表条目消息由ONOS根据每个应用程序生成的流规则并基于与p4-tutorial-pipeconf相关联的P4Info生成。

      If you prefer to watch the BMv2 log updating in real time, you can use the following command to print on screen all new messages:
      如果您希望实时观看BMv2日志记录,可以使用以下命令在屏幕上打印所有新消息:

      $ bm-log s1
      

      This command will show the log of the BMv2 switch in Mininet with name “s1”.
      此命令将显示名为“s1”的Mininet中BMv2开关的日志。

      If needed, you can run BMv2 with debug logging enabled by passing the sub-argument loglevel=debug when starting Mininet. For example:
      如果需要,您可以通过在启动Mininet时传递子参数loglevel = debug来运行BMv2并启用debug logging。例如:

      $ sudo -E mn [...] --switch onosbmv2,loglevel=debug,pipeconf=p4-tutorial-pipeconf [...]
      

      Debug logging in BMv2 is useful to observe the life of a packet inside the pipeline, e.g. showing the header fields extracted by the parser for a specific packet, the tables used to process the packets, matching table entries (if any), etc.
      BMv2中的调试日志记录对于观察管道内数据包的生命周期非常有用,
      例如:显示解析器为特定数据包提取的标头字段,用于处理数据包的表,匹配表条目(如果有)等。

    5. Check the flow rules inserted by each app in ONOS. In the ONOS CLI type:
      检查ONOS中每个应用程序插入的流程规则。在ONOS CLI类型中:

      onos> flows -s
      

      You should see 3 flow rules:
      你应该看到3个流程规则:

      deviceId=device:bmv2:s1, flowRuleCount=3
          ADDED, bytes=0, packets=0, table=0, priority=40000, selector=[ETH_TYPE:arp], treatment=[immediate=[OUTPUT:CONTROLLER], clearDeferred]
          ADDED, bytes=0, packets=0, table=0, priority=40000, selector=[ETH_TYPE:bddp], treatment=[immediate=[OUTPUT:CONTROLLER], clearDeferred]
          ADDED, bytes=0, packets=0, table=0, priority=40000, selector=[ETH_TYPE:lldp], treatment=[immediate=[OUTPUT:CONTROLLER], clearDeferred]
      

      These flow rules are installed automatically for each device by the Proxy ARP and LLDP Link Discovery apps. The first one is used to intercept ARP requests (selector=[ETH_TYPE:arp]), which are sent to the controller (treatment=[immediate=[OUTPUT:CONTROLLER]), who in turn will reply with an ARP response or broadcast the requests to all hosts.
      The other two flow rules are used to intercept LLDP and BBDP packets (for the purpose of link discovery).
      Proxy ARP和LLDP Link Discovery应用程序会自动为每台设备安装这些流规则。
      第一个用于拦截ARP请求(selector = [ETH_TYPE:arp]),
      它们被发送到控制器(treatment = [immediate = [OUTPUT:CONTROLLER]),
      而后者将用ARP回复 响应或向所有主机广播请求。
      其他两个流规则用于拦截LLDP和BBDP报文(用于链路发现)。

      These flow rules appear to be installed on table “0”. This is a logical table number mapped by the pipeconf’s interpreter to the P4 table named t_l2_fwd in mytunnel.p4 (line 191).
      这些流规则似乎安装在表“0”上。这是pipeconf的解释器映射到 mytunnel.p4 (line 191).中的名为t_l2_fwd的P4表的逻辑表号

      This mapping is defined inPipelineInterpreterImpl.java (line 103)
      此映射在 PipelineInterpreterImpl.java (line 103)中定义

    6. Compare ONOS flow rules to the table entries installed on the BMv2 switch.
      将ONOS流规则与安装在BMv2交换机上的表条目进行比较

      We can use the BMv2 CLI to dump all table entries currently installed on the switch. On a separate terminal window type:
      我们可以使用BMv2 CLI转储当前安装在交换机上的所有表条目。在单独的终端窗口上键入:

       $ bm-cli s1
      

      This command will start the CLI for the BMv2 switch in Mininet with name “s1”.
      此命令将启动名为“s1”的mininet中bmv2开关的cli。

      On the BMv2 CLI prompt, type the following command:
      在bmv2 cli提示下,键入以下命令:

      RuntimeCmd: table_dump c_ingress.t_l2_fwd
      

      You should see exactly 3 entries, each one corresponding to a flow rule in ONOS. For example, the flow rule matching on ARP packets should look like this in the BMv2 CLI:
      您应该正好看到3个条目,每个条目对应于ONOS中的一个流程规则。
      例如,在bmv2 cli中,arp数据包上的流规则匹配应该如下所示:

      ...
      **********
      Dumping entry 0x2000002
      Match key:
      * standard_metadata.ingress_port: TERNARY   0000 &&& 0000
      * ethernet.dst_addr             : TERNARY   000000000000 &&& 000000000000
      * ethernet.src_addr             : TERNARY   000000000000 &&& 000000000000
      * ethernet.ether_type           : TERNARY   0806 &&& ffff
      Priority: 16737216
      Action entry: c_ingress.send_to_cpu -
      ...
      

      Note how the ONOS selector [ETH_TYPE:arp] has been translated to an entry matching only the header field ethernet.ether_type, while the bits of all other fields are set as “don’t care” (mask is all zeros). While the ONOS treatment[OUTPUT:CONTROLLER]has been translated to the action c_ingress.send_to_cpu.
      请注意,ONOS选择器[eth_type:arp]是如何被转换为只与头字段ethernet.ether_type匹配的条目的,而所有其他字段的位都被设置为“不关心”(掩码都是零)。
      当ONOS处理[output:controller]被转换为操作c_entress.send_to_cpu

      Important: The BMv2 CLI is a powerful tool to debug the state of a BMv2 switch. Type help to show a list of possible commands. This CLI provides also auto-completion when pressing the tab key.
      重要提示: bmv2 cli是调试bmv2开关状态的强大工具。键入help以显示可能的命令列表。
      当按下tab键时,此CLI还提供自动完成功能。

  4. It is finally time to test connectivity between the hosts of our Mininet network.
    最后是时候测试我们的迷你网络的主机之间的连接了。

    1. On the Mininet prompt, start a ping between host1 and host2:
      在MiniNet提示下,在host1和host2之间启动ping

      mininet> h1 ping h2
      

      The ping should NOT work, and the reason is that we did not activate yet any ONOS app providing connectivity between hosts.
      ping不应该工作,原因是我们还没有激活任何提供主机间连接的ONOS应用程序。

    2. While leaving the ping running on Mininet, activate the Reactive Forwarding app using the ONOS CLI:
      在MiniNet上运行ping时,使用ONOS CLI激活反应转发应用程序

      onos> app activate org.onosproject.fwd
      

      Once activated, you should see the the ping working. Indeed, this app installs the necessary flow rules to forward packets between the two hosts.
      一旦激活,您应该看到ping正在工作。实际上,这个应用程序安装了必要的流规则来在两台主机之间转发数据包。

    3. Use steps 3.v and 3.vi to check the new flow rules.
      使用步骤 3.v 和 3.vi检查新的流程规则

      You should see 3 new flow rules.
      您应该看到3个新的流程规则。

      The Reactive Forwarding app works in the following way. It installs a low priority flow rule to intercepts all IPv4 packets via asend_to_cpu action ([OUTPUT:CONTROLLER] in ONOS). When a packet is received by the control plane, the packet is processed by the app, which in turn, by querying the Topology service and the Host Location service is ONOS, computes the shortest path between the two hosts, and installs higher priority flow rules on each hop to forward packets between the two hosts (after having re-injected that packet in the network via a packet-out).
      反应转发应用程序的工作方式如下。它安装了一个低优先级的流规则,通过send_to_cpu操作(在ONOS中为[OUTPUT:CONTROLLER])截获所有的IPv4数据包。
      当控制平面接收到一个数据包时,该数据包由应用程序进行处理,进而通过查询拓扑服务和主机位置服务为ONOS,计算两台主机之间的最短路径,并在每个跃点上安装更高优先级的流规则,以便在两台主机之间转发数据包(在重新注入该PAC之后在网络中通过数据包输出)。

  5. Congratulations, you completed the first exercise of the ONOS+P4 tutorial!
    恭喜你,你完成了ONOS+P4教程的第一个练习!

    To kill ONOS, press ctrl-c in the ONOS log terminal window. To kill Mininet, press ctrl-d in the Mininet CLI or type exit.
    要终止ONOS,请在OnOS日志终端窗口中按ctrl-c
    要终止mininet,请在mininet cli中按 ctrl-d ,或键入exit

Bonus exercise

奖金练习

As a bonus exercise, you can re-run Mininet with a larger topology to see how Exercise 1 works with a more complex topology.
作为一个额外的练习,您可以使用更大的拓扑重新运行MiniNet,以了解练习1如何使用更复杂的拓扑。

  1. Rerun the steps in Exercise 1, replacing step 3.i. with the following:
    重新运行练习1中的步骤,将步骤3.i.替换为以下内容:

    $ sudo -E mn --custom $BMV2_MN_PY --switch onosbmv2,pipeconf=p4-tutorial-pipeconf --topo tree,3 --controller remote,ip=127.0.0.1
    

    By using the argument --topo we are telling Mininet to emulate a Tree topology with depth 3, i.e. with 7 switches, 6 links, and 8 hosts.
    通过使用参数--topo ,我们告诉MiniNet模拟深度为3的树拓扑,即使用7个交换机、6个链接和8个主机。

    Important: due to the limited resources of the VM, when executing many switches in Mininet, it might happen that some flow rules are not installed correctly on the switch (showing state PENDING_ADD when using ONOS command flows). In this case, ONOS provides an automatic reconciliation mechanism that tries to re-install the failed entries. To force ONOS to perform this process more often, make sure to apply step 2.v before starting Mininet.
    重要提示: 由于虚拟机资源有限,在MiniNet中执行多个交换机时,可能会出现某些流规则未正确安装在交换机上(使用onos命令flows时显示状态PENDING_ADD)。
    在这种情况下,ONOS提供自动调节机制,尝试重新安装失败的条目。
    要强制ONOS更频繁地执行此过程,请确保在启动MiniNet之前应用步骤2.v

  2. After you activate the Reactive Forwarding app as in step 4.ii., you can ping all hosts in the network using the following Mininet command:
    按照步骤4.ii激活反应转发应用程序后,可以使用以下mininnet命令ping网络中的所有主机:

    mininet> pingall
    

    If everything went well, ping should work for every host pair in the network.
    如果一切顺利,ping应该适用于网络中的每个主机对。

  3. You can visualize the topology using the ONOS web UI.
    您可以使用ONOSWebUI可视化拓扑。

    Open a browser from within the tutorial VM (e.g. Firefox) to http://127.0.0.1:8181/onos/ui/. When asked, use the username onos and password rocks. You should see a nice tree topology.
    从教程vm(例如firefox)中打开浏览器
    http://127.0.0.1:8181/onos/ui/当被询问时,
    请使用用户名 onos和密码rocks。你应该看到一个很好的树拓扑结构。

    While here, feel free to interact with and discover the ONOS UI. For more information on how to use the ONOS web UI please refer to this guide:
    https://wiki.onosproject.org/x/OYMg
    在这里,您可以自由地与ONOS用户界面进行交互和发现。
    有关如何使用ONOS Web UI的详细信息,请参阅本指南:
    https://wiki.onosproject.org/x/oymg

你可能感兴趣的:(onos)