SDN IN ACTION: Practice SDN/OpenFlow with LINC-Switch and OpenDaylight
薛国锋 [email protected]
本次实验,重点学习了Erlang语言、LINC软件OpenFlow交换机以及OpenDaylight开源控制器。
Last time we had built anemulated environment based on ONOS and Mininet, today we are going to play with LINC-Switch and OpenDaylight to have a deep understanding of SDN/OpenFlow, and we will also try to get some hands-on experiences with RESTful APIs and RestConf. 3 VMs - LINC-Swtich, GNS3 and OpenDaylight are created in this lab and below is the physical and logical design and topology:
1 Set up the VM-LINC-Switch
https://github.com/FlowForwarding/LINC-Switch
https://klyr.quicheaters.org/blog/playing-with-the-erlang-linc-switch.html
Erlang is a programming language used to build massively scalable soft real-time systems with requirements on high availability. Some of its uses are in telecoms, banking, e-commerce, computer telephony and instant messaging (such as What‘s App). Erlang‘s runtime system has built-in support for concurrency,distribution and fault tolerance.
Install defaultJRE/JDK:
sudo apt-get update
sudo apt-get install default-jre
sudo apt-get install default-jdk
Install some required system packages to build Erlang from sources:
sudo apt-get install gcc wgetmake autoconf openssl libssl1.0.0 libssl-dev libncurses5 libncurses5-dev
Download Erlang/OTP17.0 Source Files and unpack into the home directory:
http://www.erlang.org/downloads/17.0
Comple and Install Erlang/OTP 17.0:
cd ~/otp_src_17.0
./configure
make
sudo make install
LINC is a pure OpenFlow software switch written in Erlang.It‘s implemented in operating system‘s userspace as an Erlang node. Such approach is not the most efficient one, but it gives a lot of flexibility and allows quick development and testing of new OpenFlow features.
Install theadditional libraries and tools to build LINC-Swtich from sources:
sudo apt-get install git-core bridge-utils libpcap0.8 libpcap-dev libcap2-bin uml-utilities
Clone the gitrepository:
git clone https://github.com/FlowForwarding/LINC-Switch.git
Compile LINC-Switch:
cd ~/LINC-Switch/rel/files
mv sys.config.orig sys.config
cd ~/LINC-Switch
make
Virtual Ethernet interfaces which always come in pair, can serveas the both ends of a tunnel and connect two entities in Linux. Create 3 pairs ofveth interfaces for 3 LINC-Swtiches:
sudo ip link add veth12 type veth peer name veth21
sudo ip link set veth12 up
sudo ip link set veth21 up
sudo ip link add veth13 typeveth peer name veth31
sudo ip link set veth13 up
sudo ip link set veth31 up
sudo ip link add veth23 typeveth peer name veth32
sudo ip link set veth23 up
sudo ip link set veth32 up
The config_gen script supports configuring multiple logicalswitches as well as using eth, tap and veth interfaces. Create 3 switches with the same controller and generate the configuration file to start LINC-Swtich:
cd ~
./LINC-Switch/scripts/config_gen-s 1 eth1 veth12 veth13 -s 2 eth2 veth21 veth23 -s 3 eth3 veth31 veth32 -c tcp:192.168.100.129:6633 -o ~/LINC-Switch/rel/linc/releases/1.0/sys.config
// s1 with eth1 connecting tos2 by veth12 and s3 by veth13
// s2 with eth2 connecting tos1 by veth21 and s3 by veth23
// s3 with eth3 connecting tos1 by veth31 and s2 by veth32
// s1, s2 and s3 connecting toOpenDaylight by tcp:192.168.100.129:6633
~/LINC-Switch/rel/linc/releases/1.0/sys.config which uses Erlang configuration syntax, is automatically generated as the configuration file to start LINC-Swtich:
[{linc,
[{of_config,enabled}, // enabled or disabled
{sync_routing,true},
{capable_switch_ports,
[{port,1,[{interface,"eth1"}]},
{port,2,[{interface,"veth12"}]},
{port,3,[{interface,"veth13"}]},
{port,4,[{interface,"eth2"}]},
{port,5,[{interface,"veth21"}]},
{port,6,[{interface,"veth23"}]},
{port,7,[{interface,"eth3"}]},
{port,8,[{interface,"veth31"}]},
{port,9,[{interface,"veth32"}]}]},
{capable_switch_queues,[]},
{logical_switches,
[{switch,3, // s3
[{backend,linc_us4}, // linc_us4 for OpenFlow 1.3
{controllers,
[{"Switch3-Controller","192.168.100.129",6633,tcp}]},
{controllers_listener,disabled},
{queues_status,disabled},
{ports,
[{port,7,[{queues,[]}]},
{port,8,[{queues,[]}]},
{port,9,[{queues,[]}]}]}]},
{switch,2, // s2
[{backend,linc_us4},
{controllers,
[{"Switch2-Controller","192.168.100.129",6633,tcp}]},
{controllers_listener,disabled},
{queues_status,disabled},
{ports,
[{port,4,[{queues,[]}]},
{port,5,[{queues,[]}]},
{port,6,[{queues,[]}]}]}]},
{switch,1, // s1
[{backend,linc_us4},
{controllers,
[{"Switch1-Controller","192.168.100.129",6633,tcp}]},
{controllers_listener,disabled},
{queues_status,disabled},
{ports,
[{port,1,[{queues,[]}]},
{port,2,[{queues,[]}]},
{port,3,[{queues,[]}]}]}]}]}]},
{enetconf,
[{capabilities,
[{base,{1,0}},
{base,{1,1}},
{startup,{1,0}},
{‘writable-running‘,{1,0}}]},
{callback_module,linc_ofconfig},
{sshd_ip,any},
{sshd_port,1830},
{sshd_user_passwords,[{"linc","linc"}]}]},
{lager,
[{handlers,
[{lager_console_backend,info}, // replace ‘debug’ with ‘info’
{lager_file_backend,
[{"log/error.log",error,10485760,"$D0",5},
{"log/console.log",info,10485760,"$D0",5}]}]}]},
{sasl,
[{sasl_error_logger,{file,"log/sasl-error.log"}},
{errlog_type,error},
{error_logger_mf_dir,"log/sasl"},
{error_logger_mf_maxbytes,10485760},
{error_logger_mf_maxfiles,5}]},
{sync,[{excluded_modules,[procket]}]}].
Start, stop andattach LINC-Swtich :
sudo ~/LINC-Switch/rel/linc/bin/lincstart
sudo~/LINC-Switch/rel/linc/bin/linc console
sudo~/LINC-Switch/rel/linc/bin/linc attach
sudo~/LINC-Switch/rel/linc/bin/linc stop
2 Set up theVM-GNS3
The eth1, eth2 and eth3 of GNS3 are respectively connected to the eth1, eth2 and eth3 of LINC-Switch with VMware LAN Segments. Create 3 virtual routers and connect them to S1, S2 and S3 in LINC-Swtich via GNS3 Cloud:
R1#show run
interface FastEthernet0/0
ip address 10.110.0.1 255.255.0.0
R2#show run
interface FastEthernet0/0
ip address 10.110.0.2 255.255.0.0
R3#show run
interface FastEthernet0/0
ip address 10.110.0.3 255.255.0.0
3 Set up the VM-OpenDaylight and test the network
While both adopting Java, OSGi and Karaf, OpenDaylight focuses on bringing legacy (BGP, SNMP, and such) and new networks (i.e., OpenFlow andSDN) together whereas ONOS focuses on the performance aspects and theclustering to increase the availability and scalability. Before installingOpenDaylight, install default JRE/JDK first.
Download the official OpenDaylight release (distribution-karaf-0.6.0-Carbon.tar.gz) for production:
Unpack into the home directory and run it:
Install the the necessary OpenDaylight features withfollowing commands:
feature:install odl-aaa-authn odl-restconf-allodl-dlux-core odl-dluxapps-yangman odl-dluxapps-topologyodl-l2switch-all webconsole odl-mdsal-apidocs
You can check the below web link for all the OpenDaylightfeatures and descritions:
Open a brower on the hostsystem and enter the URL of OpenDaylight ( User/Password:admin/admin ):
http://192.168.100.129:8181/index.html
The topology tab displays a graphical representationof network topology created:
YANG is a human-readablelanguage for describing data device and service models. ODL dynamicallygenerates REST APIs from YANG models (referred to as RESTCONF), thus providingODL apps developers with an immediate baseline set of APIs. YANGMAN is an ODLapplication offering dynamically generated UI forms and native JSON representationbased on RESTCONF APIs:
Try different RESTful APIs in OpenDaylight:
http://192.168.100.129:8181/restconf/operational/network-topology:network-topology
Simple REST Client is an extension for Google Chrome to help construct custom HTTP requests to directly test the web services. Download is available at: http://chrome.google.com/extensions/detail/fhjcajmcbmldlhcimfajhfbgofnpcjmb
Try the following commands in LINC-Switch:
([email protected])1> rp(application:get_all_key(linc)). // show the running configuration
([email protected])2>linc:ports(1). // showall the ports of 1 ( Switch ID)
([email protected])3>linc_logic:get_datapath_id(2). //show the datapath ID of 2 ( Switch ID)
Check the IP connectivity among virtual routers in GNS3: