如何设定/etc/config/network,让Openwrt router成为 Open FLow Switch

1,857 views
Skip to first unread message

林清祥

unread,
May 27, 2015, 11:09:25 PM5/27/15
to sdnd...@googlegroups.com
大家好,

我已经在HiWiFi j1s(http://www.hiwifi.com/j1s-para)上编译Open vSwitch,确定在预设的网络设定下, OVS可以通过LAN口连接Floodlight。

我现在的问题是如何修改/etc/config/network,使得LAN Port 1可以与Floodlight所在的机器正常通信,而LAN Port 2~4和“无线端口”提供给OVS作为对外端口。

刚接触Openwrt,所以我对Openwrt上ifconfig -a输出的interface如何对应到物理端口(WAN port 和 LAN port 1~4)也不是很了解。

能否请大家抽空帮忙指导一下,谢谢!

Openwrt的预设配置/etc/config/network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdea:fa5f:ba69::/48'

config interface 'lan'
        option ifname 'eth0.1'
        option force_link '1'
        option macaddr '00:0c:43:76:20:a0'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option ifname 'eth0.2'
        option force_link '1'
        option macaddr '00:0c:43:76:20:a1'
        option proto 'dhcp'

config interface 'wan6'
        option ifname 'eth0.2'
        option proto 'dhcpv6

通过命令行 swconfig dev mt7620 show列印出的输出:
root@HiWiFi:~# swconfig dev mt7620 show
Global attributes:
 enable_vlan
: 1
Port 0:
 pvid
: 2
 link
: port:0 link:up speed:100baseT full-duplex 
Port 1:
 pvid
: 1
 link
: port:1 link:up speed:10baseT half-duplex 
Port 2:
 pvid
: 1
 link
: port:2 link:down
Port 3:
 pvid
: 1
 link
: port:3 link:down
Port 4:
 pvid
: 1
 link
: port:4 link:up speed:10baseT half-duplex 
Port 5:
 pvid
: 1
 link
: port:5 link:down
Port 6:
 pvid
: 1
 link
: port:6 link:up speed:1000baseT full-duplex 
Port 7:
 pvid
: 0
 link
: port:7 link:down
VLAN 
1:
 vid
: 1
 ports
: 1 2 3 4 5 6t 
VLAN 
2:
 vid
: 2
 ports
: 0 6t

ifconfig -a 

br-lan    Link encap:Ethernet  HWaddr 00:0C:43:76:20:A0  
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:43ff:fe76:20a0/64 Scope:Link
          inet6 addr: fdea:fa5f:ba69::1/60 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:25641 errors:0 dropped:0 overruns:0 frame:0
          TX packets:25370 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2991000 (2.8 MiB)  TX bytes:6501566 (6.2 MiB)

eth0      Link encap:Ethernet  HWaddr 00:0C:43:76:20:A0  
          inet6 addr: fe80::20c:43ff:fe76:20a0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:795250 errors:0 dropped:71 overruns:0 frame:0
          TX packets:24836 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:139689640 (133.2 MiB)  TX bytes:6594763 (6.2 MiB)
          Interrupt:5 

eth0.1    Link encap:Ethernet  HWaddr 00:0C:43:76:20:A0  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28720 errors:0 dropped:0 overruns:0 frame:0
          TX packets:23467 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:3560626 (3.3 MiB)  TX bytes:6318988 (6.0 MiB)

eth0.2    Link encap:Ethernet  HWaddr 00:xC:43:xx:20:A1  
          inet addr:xxx.xx.xxx.xxx  Bcast:xxx.xxx.xxx.255  Mask:255.255.255.0
          inet6 addr: 2xx1:xxx:6xx3:2xx4:20c:xxxx:xxx:xxx/64 Scope:Global
          inet6 addr: xxxx::xxx:xxxx:xxxx:xxxx/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:765882 errors:0 dropped:92 overruns:0 frame:0
          TX packets:1099 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:121709573 (116.0 MiB)  TX bytes:149388 (145.8 KiB)

gre0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-50-E8-00-00-00-00-00-00-00-00  
          NOARP  MTU:1476  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

gretap0   Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          BROADCAST MULTICAST  MTU:1462  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:188 errors:0 dropped:0 overruns:0 frame:0
          TX packets:188 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:16168 (15.7 KiB)  TX bytes:16168 (15.7 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:0C:43:76:20:A0  
          inet6 addr: fe80::20c:43ff:fe76:20a0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3944 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:715296 (698.5 KiB)
------------------
——
Thanks.

Best Regards,

LIN Qingxiang(林清祥)
------
Graduate
College of Mathematics and Computer Science, FZU
 

Ping Chun Huang

unread,
May 28, 2015, 11:25:09 AM5/28/15
to 林清祥, sdnd...@googlegroups.com
hi,

=>我现在的问题是如何修改/etc/config/network,使得LAN Port
1可以与Floodlight所在的机器正常通信,而LAN Port 2~4和“无线端口”提供给OVS作为对外端口。

利用 out-of-band 的設計方式, 不要把 lan port 1 add-port 進 ovs, 且另外指定 ip 跟
floodlight做溝通, 記得 routing table 要改好

謝謝
> --
> Welcome to http://sdnds.tw/
> ---
> 這是 Google 網上論壇針對「SDNDS-tw」群組發送的訂閱通知郵件。
> 如要取消訂閱這個群組並停止接收來自這個群組的郵件,請傳送電子郵件到 sdnds-tw+u...@googlegroups.com
> 如要在這個群組張貼留言,請傳送電子郵件到 sdnd...@googlegroups.com
> 請前往以下網址造訪這個群組:http://groups.google.com/group/sdnds-tw
> 如要在網路上查看這項討論,請造訪
> https://groups.google.com/d/msgid/sdnds-tw/40f36457-0991-4a43-bd42-ecc9b8c72890%40googlegroups.com
> 如需更多選項,請前往:https://groups.google.com/d/optout

林清祥

unread,
May 28, 2015, 11:41:11 AM5/28/15
to sdnd...@googlegroups.com, woni...@gmail.com
Hi,

我现在的问题在于如何把LAN Port 1~4与ifconfig -a打印的interface对应起来。
比如:
Lan port 1 --> eth0
Lan port 2 --> eth1
可 现在的Lan port 与 interface 好像不一一对应。

在 2015年5月28日星期四 UTC+8下午11:25:09,Ping Chun Huang写道:

Ping Chun Huang

unread,
May 28, 2015, 11:57:53 AM5/28/15
to 林清祥, sdnd...@googlegroups.com
hi,

抱歉我沒看清楚,

swconfig 只是 logical port number 而已 實際上不一定是按照我們所見的順序對照 interface

所以我自己是ㄧ個一個 port 測試的, watch ip link |grep up -i

不知道其他人有沒有比較好的方式

謝謝

Ping-Chun Huang 黃秉鈞 pichuang
http://blog.night9.cc

Wireless Internet Laboratory
Computer Center, Department of Computer Science
National Chiao Tung University
> https://groups.google.com/d/msgid/sdnds-tw/1d1d2a42-c7b7-448b-96d4-b7ad7cd21997%40googlegroups.com
> 如需更多選項,請前往:https://groups.google.com/d/optout

Qingxiang Lin(林清祥)

unread,
May 28, 2015, 12:13:26 PM5/28/15
to Ping Chun Huang, sdnds-tw
Hi, 
 
明天会使用你的方法试试看,不过根据现在的设定,我发现eth0.2对应的是WAN Port, 而eth0.1对应的是LAN Port 1~4,一个interface对应四个LAN port,我不是很明白其中映射的原理。


---原始邮件---
发件人: "Ping Chun Huang "<pich...@cs.nctu.edu.tw>
发送时间: 2015年05月28日 23:57:07
收件人: "林清祥"<woni...@gmail.com>;
抄送: "sdnds-tw"<sdnd...@googlegroups.com>;
主题: Re: [sdnds-tw] 如何设定/etc/config/network,让Openwrt router成为 Open FLow Switch

hi,

抱歉我沒看清楚,

swconfig 只是 logical port number 而已 實際上不一定是按照我們所見的順序對照 interface

所以我自己是ㄧ個一個 port 測試的, watch ip link |grep up -i

不知道其他人有沒有比較好的方式

謝謝

Ping-Chun Huang 黃秉鈞 pichuang
http://blog.night9.cc

Wireless Internet Laboratory
Computer Center, Department of Computer Science
National Chiao Tung University


2015-05-28 23:41 GMT+08:00 林清祥 <woni...@gmail.com
>:
> Hi,
>
> 我现在的问题在于如何把LAN Port 1~4与ifconfig -a打印的interface对应起来。
> 比如:
> Lan port 1 --> eth0
> Lan port 2 --> eth1
> 可 现在的Lan port 与 interface 好像不一一对应。
>
> 在 2015年5月28日星期四 UTC+8下午11:25:09,Ping Chun Huang写道:
>>
>> hi,
>>
>> =>我现在的问题是如何修改/etc/config/network,使得LAN Port
>> 1可以与Floodlight所在的机器正常通信,而LAN Port 2~4和“无线端口”提供给OVS作为对外端口。
>>
>> 利用 out-of-band 的設計方式, 不要把 lan port 1 add-port 進 ovs, 且另外指定 ip 跟
>> floodlight做溝通, 記得 routing table 要改好
>>
>> 謝謝
>>
>>
>> 2015-05-28 11:09 GMT+08:00 林清祥 <woni...@gmail.com>:
>> > 大家好,
>> >
>> > 我已经在HiWiFi j1s(http://www.hiwifi.com/j1s-para)上编译Open
>> > vSwitch,确定在预设的网络设定下,
>> > OVS可以通过LAN口连接Floodlight。
>> >
>> > 我现在的问题是如何修改/etc/config/network,使得LAN Port 1可以与Floodlight所在的机器正常通信,而LAN
>> > Port
>> > 2~4和“无线端口”提供给OVS作为对外端口。
>> >
>> > 刚接触Openwrt,所以我对Openwrt上ifconfig -a输出的interface如何对应到物理端口(WAN port 和 LAN
>> > port
>> > 1~4)也不是很了解。
>> >
>> > 能否请大家抽空帮忙指导一下,谢谢!
>> >
>> > Openwrt的预设配置/etc/config/network
>> >
>> > config interface 'loopback'
>> >         option ifname 'lo'
>> >         option proto 'static'
>> >         option ipaddr '127.0.0.1'
>> >         option netmask '255.0.0.0'
>> >
>> > config globals 'globals'
>> >         option ula_prefix 'fdea:fa5f:ba69::/48'
>> >
>> > config interface 'lan'
>> >         option ifname 'eth0.1'
>> >         option force_link '1'
>> >         option macaddr '00:0c:43:76:20:a0'
>> >         option type 'bridge'
>> >         option proto 'static'
>> >         option ipaddr '192.168.1.1'
>> >         option netmask '255.255.255.0'
>> >         option ip6assign '60'
>> >
>> > config interface 'wan'
>> >         option ifname 'eth0.2'
>> >         option force_link '1'
>> >         option macaddr '00:0c:43:76:20:a1'
>> >         option proto 'dhcp'
>> >
>> > config interface 'wan6'
>> >         option ifname 'eth0.2'
>> >         option proto 'dhcpv6
>> >
>> > 通过命令行 swconfig dev mt7620 show列印出的输出:
>> > root@HiWiFi:~# swconfig dev mt7620 show
>> > Global attributes:
>> >  enable_vlan: 1
>> > Port 0:
>> >  pvid: 2
>> >  link: port:0 link:up speed:100baseT full-duplex
>> > Port 1:
>> >  pvid: 1
>> >  link: port:1 link:up speed:10baseT half-duplex
>> > Port 2:
>> >  pvid: 1
>> >  link: port:2 link:down
>> > Port 3:
>> >  pvid: 1
>> >  link: port:3 link:down
>> > Port 4:
>> >  pvid: 1
>> >  link: port:4 link:up speed:10baseT half-duplex
>> > Port 5:
>> >  pvid: 1
>> >  link: port:5 link:down
>> > Port 6:
>> >  pvid: 1
>> >  link: port:6 link:up speed:1000baseT full-duplex
>> > Port 7:
>> >  pvid: 0
>> >  link: port:7 link:down
>> > VLAN 1:
>> >  vid: 1
>> >  ports: 1 2 3 4 5 6t
>> > VLAN 2:
>> >  vid: 2
>> >  ports: 0 6t
>> >
>> > ifconfig -a
>> >
>> > br-lan    Link encap:Ethernet  HWaddr 00:0C:43:76:20:A0
>> >           inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
>> >           inet6 addr: fe80::20c:43ff:fe76:20a0/64 Scope:Link
>> >           inet6 addr: fdea:fa5f:ba69::1/60 Scope:Global
>> >           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
>> >           RX packets:25641 errors:0 dropped:0 overruns:0 frame:0
>> >           TX packets:25370 errors:0 dropped:0 overruns:0 carrier:0
>> >           collisions:0 txqueuelen:0
>> >           RX bytes:2991000 (2.8 MiB)  TX bytes:6501566 (6.2 MiB)
>> >
>> > eth0      Link encap:Ethernet  HWaddr 00:0C:43:76:20:A0
>> >           inet6 addr: fe80::20c:43ff:fe76:20a0/64 Scope:Link
>> >           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
>> >           RX packets:795250 errors:0 dropped:71 overruns:0 frame:0
>> >           TX packets:24836 errors:0 dropped:0 overruns:0 carrier:0
>> >           collisions:0 txqueuelen:1000
>> >           RX bytes:139689640 (133.2 MiB)  TX bytes:6594763 (6.2 MiB)
>> >           Interrupt:5
>> >
>> > eth0.1    Link encap:Ethernet  HWaddr 00:0C:43:76:20:A0
>> >           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
>> >           RX packets:28720 errors:0 dropped:0 overruns:0 frame:0
>> >           TX packets:23467 errors:0 dropped:0 overruns:0 carrier:0
>> >           collisions:0 txqueuelen:0
>> >           RX bytes:3560626 (3.3 MiB)  TX bytes:6318988 (6.0 MiB)
>> >
>> > eth0.2    Link encap:Ethernet  HWaddr 00:xC:43:xx:20:A1
>> >           inet addr:xxx.xx.xxx.xxx  Bcast:xxx.xxx.xxx.255
>> > Mask:255.255.255.0
>> >           inet6 addr: 2xx1:xxx:6xx3:2xx4:20c:xxxx:xxx:xxx/64
>> > Scope:Global
>> >           inet6 addr: xxxx::xxx:xxxx:xxxx:xxxx/64 Scope:Link
>> >           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
>> >           RX packets:765882 errors:0 dropped:92 overruns:0 frame:0
>> >           TX packets:1099 errors:0 dropped:0 overruns:0 carrier:0
>> >           collisions:0 txqueuelen:0
>> >           RX bytes:121709573 (116.0 MiB)  TX bytes:149388 (145.8 KiB)
>> >
>> > gre0      Link encap:UNSPEC  HWaddr
>> > 00-00-00-00-00-00-50-E8-00-00-00-00-00-00-00-00
>> >           NOARP  MTU:1476  Metric:1
>> >           RX packets:0 errors:0 dropped:0 overruns:0 frame:0
>> >           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
>> >           collisions:0 txqueuelen:0
>> >           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
>> >
>> > gretap0   Link encap:Ethernet  HWaddr 00:00:00:00:00:00
>> >           BROADCAST MULTICAST  MTU:1462  Metric:1
>> >           RX packets:0 errors:0 dropped:0 overruns:0 frame:0
>> >           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
>> >           collisions:0 txqueuelen:1000
>> >           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
>> >
>> > lo        Link encap:Local Loopback
>> >           inet addr:127.0.0.1  Mask:255.0.0.0
>> >           inet6 addr: ::1/128 Scope:Host
>> >           UP LOOPBACK RUNNING  MTU:65536  Metric:1
>> >           RX packets:188 errors:0 dropped:0 overruns:0 frame:0
>> >           TX packets:188 errors:0 dropped:0 overruns:0 carrier:0
>> >           collisions:0 txqueuelen:0
>> >           RX bytes:16168 (15.7 KiB)  TX bytes:16168 (15.7 KiB)
>> >
>> > wlan0     Link encap:Ethernet  HWaddr 00:0C:43:76:20:A0
>> >           inet6 addr: fe80::20c:43ff:fe76:20a0/64 Scope:Link
>> >           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
>> >           RX packets:0 errors:0 dropped:0 overruns:0 frame:0
>> >           TX packets:3944 errors:0 dropped:0 overruns:0 carrier:0
>> >           collisions:0 txqueuelen:1000
>> >           RX bytes:0 (0.0 B)  TX bytes:715296 (698.5 KiB)
>> > ------------------
>> > ——
>> > Thanks.
>> >
>> > Best Regards,
>> >
>> > LIN Qingxiang(林清祥)
>> > ------
>> > Graduate
>> > College of Mathematics and Computer Science, FZU
>> >
>> >
>> > --
>> > Welcome to http://sdnds.tw/
。
> 如要在網路上查看這項討論,請造訪
> https://groups.google.com/d/msgid/sdnds-tw/1d1d2a42-c7b7-448b-96d4-b7ad7cd21997%40googlegroups.com。
> 如需更多選項,請前往:https://groups.google.com/d/optout

Ping Chun Huang

unread,
May 28, 2015, 12:23:00 PM5/28/15
to Qingxiang Lin(林清祥), Ping Chun Huang, sdnds-tw
hi,

eth0.1 是指 vlan1 interface
eth0.2 是指 vlan2 interface

對應到 physical port 的列表就是你上面列的 swconfig output

VLAN 1:
vid: 1
ports: 1 2 3 4 5 6t
VLAN 2:
vid: 2
ports: 0 6t

http://wiki.openwrt.org/doc/uci/network/switch

這篇應該可以幫助你


Ping-Chun Huang 黃秉鈞 pichuang
http://blog.night9.cc

Wireless Internet Laboratory
Computer Center, Department of Computer Science
National Chiao Tung University


> https://groups.google.com/d/msgid/sdnds-tw/tencent_C579112341210C3E4DC40B33%40qq.com
> 如需更多選項,請前往:https://groups.google.com/d/optout

林清祥

unread,
May 28, 2015, 11:23:15 PM5/28/15
to sdnd...@googlegroups.com, pich...@cs.nctu.edu.tw
Hi,

非常感谢,现在明白vlan interface的作用了,以及interface如何映射到实际物理端口Port,以下是我的配置,通过WAN Port将路由器(OF Switch)与控制器连接到同一个网络,
然后LAN Port 1~4通过vlan隔离开:
LAN Port 1 --> eth0.1
LAN Port 2 --> eth0.2
LAN Port 3 --> eth0.3
LAN Port 4 --> eth0.4

然后再创建OF switch br0,并把eth0.1 ~ 4添加到br0

ovs-vsctl add-br br0
ovs
-vsctl add-port br0 eth0.1
ovs
-vsctl add-port br0 eth0.2

ovs
-vsctl add-port br0 eth0.3

ovs
-vsctl add-port br0 eth0.4



config interface 'wan'                        
        option ifname
'eth0.0'                
        option force_link
'1'                  
        option macaddr
'00:0c:43:76:20:a1'    
        option proto
'dhcp'                    
                                               
config
interface 'lan1'                        
        option ifname
'eth0.1'                
        option proto
'static'            
                                         
config
interface 'lan2'                  
        option ifname
'eth0.2'            
        option proto
'static'            
                             
config
interface 'lan3'      
        option ifname
'eth0.3'
        option proto
'static'
                             
config
interface 'lan4'      
        option ifname
'eth0.4'
        option proto
'static'
                             
config
interface 'lan4'      
        option ifname
'eth0.4'
        option proto
'static'
                             
config
switch                
        option name switch0  
        option reset
1        
        option emable_vlan
1  
                             
config switch_vlan            
        option device switch0
        option vlan
'0'      
        option ports
'0 6t'


config switch_vlan            
        option device switch0
        option vlan
'1'      
        option ports
'1 6t'  
                             
config switch_vlan            
        option device switch0
        option vlan
'2'      
        option ports
'2 6t'  
                             
config switch_vlan            
        option device switch0
        option vlan
'3'      
        option ports
'3 6t'  
                             
config switch_vlan          
        option device switch0
        option vlan
'4'      
        option ports
'4 6t'


在 2015年5月29日星期五 UTC+8上午12:23:00,Ping Chun Huang写道:
Reply all
Reply to author
Forward
0 new messages