示例:在 MX 系列路由器上启用 OpenFlow
OpenFlow 是一种开放标准,允许您通过在沿路径的每个设备中创建、删除和修改流来控制网络中的信息流。此示例说明如何在运行 Junos OS 的 MX240 路由器上配置 OpenFlow 支持。
要求
此示例使用以下硬件和软件组件:
运行 Junos OS 13.3 或更高版本的 MX240 路由器
OpenFlow 软件包,其软件包版本与安装设备的 Junos OS 版本匹配
路由器与 OpenFlow 控制器之间的 TCP 连接
路由器的管理接口和管理网络之间的连接,可从 OpenFlow 控制器 IP 地址访问
概述
在此示例中,您在 MX240 路由器上配置对 OpenFlow 的支持。路由器有三个仅参与 OpenFlow 的接口:ge-1/0/0.0、ge-1/1/0.0 和 xe-0/0/0.0。您首先使用物理链路层封装 ethernet-bridge
类型和协议系列 bridge
将接口配置为第 2 层接口。
MX 系列路由器需要单独的虚拟交换机路由实例,以将 OpenFlow 流量与正常网络流量隔离。此示例在层次结构级别使用实例类型virtual-switch
[edit routing-instances]
配置虚拟交换机路由实例 rt-bd-1。在路由实例中,网桥域of-bridge
包括参与 OpenFlow 的所有逻辑接口。
您可以在层级配置 OpenFlow 虚拟交换机和 OpenFlow 协议语句 [edit protocols openflow]
。在此示例中,虚拟交换机 OFwitch1 通过 IP 地址为 172.16.1.1 的 TCP 连接连接到控制器。虚拟交换机配置必须包含参与 OpenFlow 的所有逻辑接口,而 OpenFlow 流量只会进出这些接口。
在 OpenFlow 配置中,语句 default-action
指示交换机对没有匹配流条目的数据包必须采取的操作。如果省略该 default-action
语句,则默认操作为 packet-in
,它表示必须将没有匹配流条目的数据包发送至控制器进行处理。此示例对没有匹配流条目 packet-in
的数据包显式配置默认操作。
此示例还配置 OpenFlow 追踪选项。在这种情况下, flag all
语句表示应捕获并记录所有 OpenFlow 追踪事件。由于此示例没有为日志文件配置特定的文件名,OpenFlow 跟踪消息会记录在默认的 OpenFlow 日志文件 /var/log/ofd 中。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,将命令复制并粘贴到层级的 [edit]
CLI 中,然后从配置模式进入 commit
。
set interfaces ge-1/0/0 encapsulation ethernet-bridge unit 0 family bridge set interfaces ge-1/1/0 encapsulation ethernet-bridge unit 0 family bridge set interfaces xe-0/0/0 encapsulation ethernet-bridge unit 0 family bridge set routing-instances rt-bd-1 instance-type virtual-switch set routing-instances rt-bd-1 bridge-domains of-bridge vlan-id none set routing-instances rt-bd-1 bridge-domains of-bridge interface ge-1/0/0.0 set routing-instances rt-bd-1 bridge-domains of-bridge interface ge-1/1/0.0 set routing-instances rt-bd-1 bridge-domains of-bridge interface xe-0/0/0.0 set protocols openflow switch OFswitch1 controller address 172.16.1.1 set protocols openflow switch OFswitch1 controller protocol tcp set protocols openflow switch OFswitch1 interfaces ge-1/0/0.0 set protocols openflow switch OFswitch1 interfaces ge-1/1/0.0 set protocols openflow switch OFswitch1 interfaces xe-0/0/0.0 set protocols openflow switch OFswitch1 default-action packet-in set protocols openflow traceoptions flag all
程序
逐步过程
要配置对 OpenFlow 的支持:
将 OpenFlow 接口配置为第 2 层接口。
[edit interfaces] user@host# set ge-1/0/0 encapsulation ethernet-bridge unit 0 family bridge user@host# set ge-1/1/0 encapsulation ethernet-bridge unit 0 family bridge user@host# set xe-0/0/0 encapsulation ethernet-bridge unit 0 family bridge
配置虚拟交换机路由实例。
[edit routing-instances] user@host# set rt-bd-1 instance-type virtual-switch user@host# set rt-bd-1 bridge-domains of-bridge vlan-id none user@host# set rt-bd-1 bridge-domains of-bridge interface ge-1/0/0.0 user@host# set rt-bd-1 bridge-domains of-bridge interface ge-1/1/0.0 user@host# set rt-bd-1 bridge-domains of-bridge interface xe-0/0/0.0
配置 OpenFlow 控制器 IP 地址和连接协议。
[edit protocols openflow switch OFswitch1] user@host# set controller address 172.16.1.1 user@host# set controller protocol tcp
在此虚拟交换机实例下,配置参与 OpenFlow 的逻辑接口。
[edit protocols openflow switch OFswitch1] user@host# set interfaces ge-1/0/0.0 user@host# set interfaces ge-1/1/0.0 user@host# set interfaces xe-0/0/0.0
为没有匹配流条目的数据包配置默认操作。
[edit protocols openflow switch OFswitch1] user@host# set default-action packet-in
配置 OpenFlow 追踪选项。
[edit protocols openflow] user@host# set traceoptions flag all
提交配置。
[edit] user@host# commit
结果
在配置模式下,输入 、 show protocols openflow
和show routing-instances
命令,show interfaces
以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以更正配置。
user@host# show interfaces ge-1/0/0 { encapsulation ethernet-bridge; unit 0 { family bridge; } } ge-1/1/0 { encapsulation ethernet-bridge; unit 0 { family bridge; } } xe-0/0/0 { encapsulation ethernet-bridge; unit 0 { family bridge; } }
user@host# show protocols openflow switch OFswitch1 { default-action packet-in; interfaces { ge-1/0/0.0; ge-1/1/0.0; xe-0/0/0.0; } controller { address 172.16.1.1; protocol tcp; } } traceoptions { flag all; }
user@host# show routing-instances rt-bd-1 { instance-type virtual-switch; bridge-domains { of-bridge { vlan-id none; interface ge-1/0/0.0; interface ge-1/1/0.0; interface xe-0/0/0.0; } } }
验证
确认配置工作正常。
验证 OpenFlow 控制器连接是否已开启
目的
验证 OpenFlow 控制器连接是否已开启。
行动
发出 show openflow controller
操作模式命令,并验证控制器连接状态是否为 up
。由于虚拟交换机配置只有一个控制器,因此虚拟交换机应在您提交配置后自动启动与控制器的连接。
user@host> show openflow controller Openflowd controller information: Controller socket: 11 Controller IP address: 172.16.1.1 Controller protocol: tcp Controller port: 6633 Controller connection state: up Number of connection attempt: 1 Controller role: equal
意义
除了有关控制器 up
的其他信息外,输出还显示 OpenFlow 控制器的连接状态。
验证 OpenFlow 接口是否已启动
目的
验证 OpenFlow 接口是否已开启。
行动
发出 show openflow interfaces
操作模式命令,并验证每个 OpenFlow 接口的状态是否为 Up
。
user@host> show openflow interfaces Switch name: OFswitch1 Interface Name: ge-1/0/0.0 Interface port number: 41507 Interface Hardware Address: 00:00:5e:00:53:b1 Interface speed: 1Gb Full-duplex Interface Auto-Negotiation: Disabled Interface media type: Fiber Interface state: Up Switch name: OFswitch1 Interface Name: ge-1/1/0.0 Interface port number: 44538 Interface Hardware Address: 00:00:5e:00:53:b2 Interface speed: 1Gb Full-duplex Interface Auto-Negotiation: Disabled Interface media type: Fiber Interface state: Up Switch name: OFswitch1 Interface Name: xe-0/0/0.0 Interface port number: 45549 Interface Hardware Address: 00:00:5e:00:53:b3 Interface speed: 10Gb Full-duplex Interface Auto-Negotiation: Disabled Interface media type: Fiber Interface state: Up
意义
除了有关接口 Up
的其他信息外,输出还显示每个 OpenFlow 接口的状态。