Exercise 2 (ONOS+P4 Tutorial)
纯翻译记录
The goal of this exercise is to demonstrate how ONOS apps can be used to control any P4-defined pipeline, even those implementing custom non-standard protocols.
本练习的目标是演示如何使用ONOS应用程序控制任何P4定义的管道,甚至那些实现自定义非标准协议的管道。
Overview
概述
Similarly to exercise 1, in this example we want to provide connectivity between hosts of a network when using switches programmed with the mytunnel.p4
program. Differently from exercise 1, forwarding between hosts will be provided by the MyTunnel app, instead of Reactive Forwarding. The MyTunnel app provides connectivity by programming the data plane to forward packets using the MyTunnel
protocol.
与练习1类似,在本例中,当使用用mytunnel.p4
程序编程的交换机时,我们希望提供网络主机之间的连接。
与练习1不同,主机之间的转发将由mytunnel应用程序提供,而不是被动转发。
mytunnel应用程序通过编程数据平面来使用mytunnel协议转发数据包来提供连接。
Before starting, we suggest to open the onos/apps/p4-tutorial
directory in your editor of choice for an easier access to the different files of this exercise. For example, if using the Atom editor:
在开始之前,我们建议在您选择的编辑器中打开onos/apps/p4-tutorial
目录,
以便更轻松地访问本练习的不同文件。例如,如果使用Atom编辑器:
$ atom $ONOS_ROOT/apps/p4-tutorial/
Protocol overview
The MyTunnel protocol works by encapsulating IPv4 frames into a MyTunnel header defined as following:
MyTunnel协议的工作原理是将IPv4帧封装到定义如下的MyTunnel头中:
header my_tunnel_t {
bit<16> proto_id; /* EtherType of the original
unencapsulated Ethernet frame */
bit<32> tun_id; /* Arbitrary tunnel identifier uniquelly
representing the egress endpoint of the tunnel */
}
A switch implementing the MyTunnel protocol can forward packets using three different forwarding behaviors.
实现mytunnel协议的交换机可以使用三种不同的转发行为转发数据包。
-
Ingress: for IPv4 packets received at a edge switch, i.e. the first node in the tunnel path, the MyTunnel header is applied with an arbitrary tunnel identifier decided by the control plane.
Ingress:对于在边缘交换机(即隧道路径中的第一个节点)接收的IPv4数据包,MyTunnel头将应用由控制平面决定的任意隧道标识符。 -
Transit: for packets with the MyTunnel header processed by an intermediate node in the tunnel path. When operating in this mode, the switch simply forwards the packet by looking at the tunnel ID field.
Transit:对于由隧道路径中的中间节点处理的带有mytunnel头的数据包。
在这种模式下操作时,交换机只需通过查看隧道ID字段来转发数据包。 -
Egress: for packets with the MyTunnel header processed by the last node in the path, the switch removes the MyTunnel header before forwarding the packet to the output port.
Egress:对于路径中最后一个节点处理的带有mytunnel头的数据包,在将数据包转发到输出端口之前,交换机会删除mytunnel头。
MyTunnel pipeline overview
MyTunnel管道概述
The three forwarding behaviors described before can be achieved by inserting entries in two different tables of mytunnel.p4
, namely t_tunnel_ingress
and
t_tunnel_fwd
.
前面描述的三种转发行为可以通过在mytunnel.p4
的两个不同表中插入条目来实现,即 t_tunnel_ingress
和t_tunnel_fwd
。
-
t_tunnel_ingress
: this table is used to implement the ingress behavior. It matches on the IPv4 destination address (longest-prefix match), and provides themy_tunnel_ingress
action, which encapsulates the packet in the MyTunnel header with a given tunnel ID (action parameter). -
T_Tunnel_Ingress
:此表用于实现入口行为。它在IPv4目标地址上匹配(最长前缀匹配),并提供my_tunnel_ingress
操作,该操作使用给定的隧道ID(操作参数)封装MyTunnel头中的数据包。 -
t_tunnel_fwd
: this table is used to implement both the transit and egress behaviors. It matches on the tunnel ID, and allows two different actions,set_out_port
andmy_tunnel_egress
.set_out_port
is used to set the output port where the packet should be transmitted without further modifications. Withmy_tunnel_egress
, the packet is stripped of the MyTunnel header before setting the output port. -
T_tunnel_fwd
:此表用于实现过境和出口行为。它匹配隧道ID,并允许两种不同的操作:set_out_port
和my_tunnel_egress
。
set_out_port
用于设置输出端口,在该端口中不需要进一步修改就可以传输数据包。
使用my_tunnel_egress
,在设置输出端口之前,数据包将从我的隧道头中剥离。
MyTunnel app overview
_MyTunnel应用程序概述
To begin, open MyTunnelApp.java in your editor of choice, and familiarize with the app implementation.
开始,打开 MyTunnelApp.java 在您选择的编辑器中,熟悉应用程序的实现。
For example, if using the Atom editor:
例如,如果使用Atom编辑器:
$ atom $ONOS_ROOT/apps/p4-tutorial/mytunnel/src/main/java/org/onosproject/p4tutorial/mytunnel/MyTunnelApp.java
The MyTunnel app works by registering an event listener with the ONOS Host Service (class InternalHostListener
at line 308). This listener is used to notify the MyTunnel app every time a new host is discovered. Host discovery is performed by means of two ONOS core services: Host Location Provider and Proxy-ARP app. Each time an ARP request is received (via packet-in), ONOS learns the location of the sender of the ARP request, before generating an ARP reply or forwarding the requests to other hosts. When learning the location of a new host, ONOS informs all apps that have registered a listener with an HOST_ADDED
event.
MyTunnel应用程序通过向ONOS hostservice注册事件侦听器(第308行的class InternalHostListener
)来工作。
此侦听器用于在每次发现新主机时通知MyTunnel应用程序。主机发现通过两个ONOS核心服务执行:主机位置提供程序和代理ARP应用程序。
每次接收到一个ARP请求(通过数据包输入),ONOS在生成一个ARP回复或将请求转发给其他主机之前,就知道了ARP请求发送者的位置。
当了解新主机的位置时,ONOS会通知所有已向HOST_ADDED
事件注册侦听器的应用程序。
Once an HOST_ADDED
event is notified to the MyTunnel app, this creates two unidirectional tunnels between that host and any other host previously discovered. For each tunnel, the app computes the shortest path between the two hosts (method provisionTunnel
at line 128), and for each switch in the path it installs flow rules for the t_tunnel_ingress
table (method insertTunnelIngressRule
at line 182), and/or the t_tunnel_fwd
table (method insertTunnelForwardRule
at line 219), depending on the position of the switch in the path, the app will install rule to perform the ingress, transit, or egress behaviors.
一旦HOST_ADDED
事件通知到mytunnel应用程序,这将在该主机和以前发现的任何其他主机之间创建两个单向隧道。对于每个隧道,应用程序计算两个主机之间的最短路径(第128行的方法provisionTunnel
),对于路径中的每个开关,它为 t_tunnel_ingress
表(第182行的方法insertTunnelIngressRule
)和/或t_tunnel_fwd
表(第219行的方法insertTunnelForwardRule
)安装流量规则,具体取决于订单在路径中放置开关,应用程序将安装规则来执行进入、传输或退出行为。
Exercise steps
练习步骤
-
Complete the implementation of the MyTunnel app:
完成mytunnel应用程序的实施:-
Open MyTunnelApp.java in your editor of choice.
在您的编辑器中打开 MyTunnelApp.java 。 -
Look for the
insertTunnelForwardRule
method (line 219).
查找insertTunnelForwardRule
方法(第219行)。 -
Complete the implementation of this method (There’s a
TODO EXERCISE
comment at line 251).
完成此方法的实现(第251行有一条TODO EXERCISE
注释)。Spoiler alert: There is a reference solution in the same directory as MyTunnelApp.java. Feel free to compare your implementation to the reference one.
spoiler alert: 与mytunnelapp.java在同一目录中有一个参考解决方案。请随意将您的实现与参考实现进行比较。
-
-
Start ONOS with and all the apps.
使用和所有应用程序启动ONOS。-
On a first terminal window, start ONOS:
在第一个终端窗口上,启动ONOS:$ cd $ONOS_ROOT $ ONOS_APPS=proxyarp,hostprovider,lldpprovider ok clean
-
On a second terminal window to access the ONOS CLI:
在第二个终端窗口上访问ONOS CLI:$ onos localhost
-
Activate the BMv2 drivers, pipeconf, and MyTunnel app:
激活BMV2 Drivered,PappeConf,and Mystell App:onos> app activate org.onosproject.drivers.bmv2 onos> app activate org.onosproject.p4tutorial.pipeconf onos> app activate org.onosproject.p4tutorial.mytunnel
Hint: To avoid accessing the CLI to start all applications, you can modify the value of the
ONOS_APPS
variable when starting ONOS. For example:
提示: 为了避免访问cli来启动所有应用程序,可以在启动onos时修改’onos_apps’变量的值。例如:$ cd $ONOS_ROOT $ ONOS_APPS=proxyarp,hostprovider,lldpprovider,drivers.bmv2,p4tutorial.pipeconf,p4tutorial.mytunnel ok clean
-
Check that all apps have been activated successfully:
检查所有应用程序是否已成功激活:onos> apps -s -a
You should see an output like this:
org.onosproject.hostprovider ... Host Location Provider org.onosproject.lldpprovider ... LLDP Link Provider org.onosproject.proxyarp ... Proxy ARP/NDP org.onosproject.drivers ... Default Drivers org.onosproject.protocols.grpc ... gRPC Protocol Subsystem org.onosproject.protocols.p4runtime ... P4Runtime Protocol Subsystem org.onosproject.p4runtime ... P4Runtime Provider org.onosproject.generaldeviceprovider ... General Device Provider org.onosproject.drivers.p4runtime ... P4Runtime Drivers org.onosproject.p4tutorial.pipeconf ... P4 Tutorial Pipeconf org.onosproject.pipelines.basic ... Basic Pipelines org.onosproject.protocols.gnmi ... gNMI Protocol Subsystem org.onosproject.drivers.gnmi ... gNMI Drivers org.onosproject.drivers.bmv2 ... BMv2 Drivers org.onosproject.p4tutorial.mytunnel ... MyTunnel Demo App
-
(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
-
-
Run Mininet to set up a tree topology of BMv2 devices, on a new terminal window type:
在新的终端窗口类型上运行MiniNet以建立BMV2设备的树拓扑结构:$ sudo -E mn --custom $BMV2_MN_PY --switch onosbmv2,pipeconf=p4-tutorial-pipeconf --topo tree,3 --controller remote,ip=127.0.0.1
-
Check that all devices, link, and hosts have been discovered correctly in ONOS.
检查所有设备、链路和主机是否已在ONOS中正确发现。-
To check the devices, on the ONOS CLI, type:
要检查设备,请在ONOS CLI上键入:onos> devices -s
The
-s
argument provides a more compact output.
-s
参数提供了更紧凑的输出。You should see 7 devices in total. Please note the driver that has been assigned to this device
bmv2:p4-tutorial-pipeconf
. It means that the device is being controlled using the driver behaviors provided the BMv2 device driver (which uses P4Runtime) and the pipeconf.
您应该看到总共7个设备。请注意已分配给该设备的驱动程序bmv2:p4-tutorial-pipeconf
。这意味着该设备正在使用提供BMV2设备驱动程序(使用p4runtime)和pipeconf的驱动程序行为进行控制。 -
Check the links:
检查链接:onos> links
The
-s
argument provides a more compact output.
-s
参数提供更紧凑的输出。You should see 12 links (the topology has 6 bidirectional links in total).
您应该看到12个链接(拓扑总共有6个双向链接)。 -
Check the hosts:
检查主机:onos> hosts -s
You should see 0 hosts, as we have not injected any ARP packet yet.
您应该看到0个主机,因为我们还没有注入任何ARP包。
-
-
Ping hosts, on the Mininet CLI, type:
ping hosts,在mininet cli上,键入:mininet> h1 ping h7
If the implementation of MyTunnelApp.java has been completed correctly, ping should work. If not, check the ONOS log for possible errors in the MyTunnel app. As a last resort, please check the reference solution in the same directory as MyTunnelApp.java and compare that to yours.
如果mytunnelapp.java的实现已经正确完成,那么ping应该可以工作。
如果没有,请检查ONOS日志中MyTunnel应用程序中可能存在的错误。
最后,请检查mytunnelapp.java目录中的参考解决方案,并将其与您的目录进行比较。 -
Look around.
环顾四周。