1、Quagga1.2.4安装配置
(1)使用sudo apt-get install quagga quagga-doc的命令安装quagga
查阅网上相关资料得知,
在Linux系统中,路由表和转发数据包的功能都是Linux内核所提供。在我们的Ubuntu16系统中,默认情况下是没有开启数据包转发功能的。
(2)开启方式:
Echo "net.ipv4.conf.all.forwarding=1" | sudo tee -a /etc/sysctl.conf
Echo "net.ipv4.conf.default.forwarding=1" | sudo tee -a /etc/sysctl.conf
sysctl –p
参考文章:安装quagga与配置quagga ospf-CSDN博客
使用Quagga在Mininet节点上进行OSPF实验_ryu mininet ospf-CSDN博客
安装完成以后,Quagga1.2.4的配置文件在/usr/share/doc/quagga-core/examples/中,每个功能对应各自配置文件,需将其拷贝至/etc/quagga并改名及权限。
(3)执行命令:
sudo cp /usr/share/doc/quagga-core/examples/zebra.conf.sample /etc/quagga/zebra.conf
sudo cp /usr/share/doc/quagga-core/examples/ospfd.conf.sample /etc/quagga/ospfd.conf
sudo cp /usr/share/doc/quagga-core/examples/zebra.conf.sample /etc/quagga/r1zebra.conf
sudo cp /usr/share/doc/quagga-core/examples/zebra.conf.sample /etc/quagga/r2zebra.conf
sudo cp /usr/share/doc/quagga-core/examples/ospfd.conf.sample /etc/quagga/r1ospfd.conf
sudo cp /usr/share/doc/quagga-core/examples/ospfd.conf.sample /etc/quagga/r2ospfd.conf
(4)拷贝Quagga运行库
sudo cp /usr/lib/quagga/* /lib
(5)启动Zebra
sudo zebra -d
(6)编辑/etc/quagga/r1ospfd.conf 和 r2ospfd.conf:
r1ospfd.conf
hostname r1_ospfd
password 123
enable password 123
router ospf
ospf router-id 10.0.3.10
network 10.0.3.0/24 area 0
network 10.0.1.0/24 area 0
debug ospf event
log stdout
r2ospfd.conf
hostname r2_ospfd
password 123
enable password 123
router ospf
ospf router-id 10.0.3.20
network 10.0.3.0/24 area 0
network 10.0.2.0/24 area 0
debug ospf event
log stdout
(7)实验程序代码testquagga.py
#!/usr/bin/python3
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Node
from mininet.log import setLogLevel, info
from mininet.cli import CLI
import time
import os
class LinuxRouter( Node ):
"A Node with IP forwarding enabled."
def config( self, **params ):
super( LinuxRouter, self).config( **params )
# Enable forwarding on the router
self.cmd( 'sysctl net.ipv4.ip_forward=1' )
def terminate( self ):
self.cmd( 'sysctl net.ipv4.ip_forward=0' )
super( LinuxRouter, self ).terminate()
class NetworkTopo( Topo ):
"A LinuxRouter connecting three IP subnets"
def build( self, **_opts ):
defaultIP1 = '10.0.3.10/24' # IP address for r0-eth1
defaultIP2 = '10.0.3.20/24'
router1 = self.addNode( 'r1', cls=LinuxRouter, ip=defaultIP1 )
router2 = self.addNode( 'r2', cls=LinuxRouter, ip=defaultIP2 )
h1 = self.addHost( 'h1', ip='10.0.1.100/24', defaultRoute='via 10.0.1.10') #define gateway
h2 = self.addHost( 'h2', ip='10.0.2.100/24', defaultRoute='via 10.0.2.20')
self.addLink(router1,router2,intfName1='r1-eth1',intfName2='r2-eth1')
self.addLink(h1,router1,intfName2='r1-eth2',params2={ 'ip' : '10.0.1.10/24' })#params2 define the eth2 ip address
self.addLink(h2,router2,intfName2='r2-eth2',params2={ 'ip' : '10.0.2.20/24' })
def run():
"Test linux router"
topo = NetworkTopo()
net = Mininet(controller = None, topo=topo ) # controller is used by s1-s3
net.start()
info( '*** Routing Table on Router:\n' )
r1=net.getNodeByName('r1')
r2=net.getNodeByName('r2')
info('starting zebra and ospfd service:\n')
r1.cmd('zebra -f /etc/quagga/r1zebra.conf -d -z /tmp/r1zebra.api -i /tmp/r1zebra.interface')
r2.cmd('zebra -f /etc/quagga/r2zebra.conf -d -z /tmp/r2zebra.api -i /tmp/r2zebra.interface')
time.sleep(1)#time for zebra to create api socket
r1.cmd('ospfd -f /etc/quagga/r1ospfd.conf -d -z /tmp/r1zebra.api -i /tmp/r1ospfd.interface')
r2.cmd('ospfd -f /etc/quagga/r2ospfd.conf -d -z /tmp/r2zebra.api -i /tmp/r2ospfd.interface')
CLI( net )
net.stop()
os.system("killall -9 ospfd zebra")
os.system("rm -f /tmp/*.api")
os.system("rm -f /tmp/*.interface")
if __name__ == '__main__':
setLogLevel( 'info' )
run()
(8)运行代码
sudo python testquagga.py
(9)刚刚开始时ping不通,等待十几秒之后再pingall即可;