在mininet上运行Quagga和搭建OSPF网络

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即可;

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Quagga软件原名是Zebra是由一个日本开发团队编写的一个以GNU版权方式发布的软件。Quagga项目开始与1996年,当前版本是0.98.4版 可以使用Quagga将linux机器打造成一台功能完备的路由器。 Quagga支持的路由协议 Quagga能够同时支持RIPv1、RIPv2、RIPng、OSPFv2、OSPFv3、BGP-4和 BGP-4+等诸多TCP/IP协议。其中: RIPv1、RIPv2、OSPFv2适用于Ipv4的自治域系统内部网络路由协议。 BGP-4是用于Ipv4的自治域系统之间 的外部网络路由协议。 RIPng、OSPFv3、BGP-4+主要扩展对Ipv6的支持。 Quagga的特性 模块化设计:Quagga基于模块化方案的设计,即对每一个路由协议使用单独的守护进程。 运行速度快:因为使用了模块化的设计,使得Quagga的运行速度比一般的路由选择程序要快。 可靠性高:在所有软件模块都失败的情况下,路由器可以继续保持连接并且daemons也会继续运行。故障诊断不必离线的状态下被诊断和更正 支持Ipv6:Quagga不仅支持Ipv4,还支持Ipv6。 Quagga的运行机制 由于Quagga采用模块化的设计,因此Quagga运行时要运行多个守护进程,包括ripd ripngd ospfd ospf6d bgpd 和Zebra。 其中,Zebra守护进程用来更新内核的路由表,而其他的守护进程负责进行相应路由选择协议的路由更新。 Quagga的好处 就路由器而论,虽然有各种硬件可用,但是费用较高。所以想到用一个运行Linux系统构件的功能丰富的路由器作为代替。Quagga路由守护程序已经使这一切变为现实。因为Quagga支持Ipv4、Ipv6和其他各式各样的协议,所以能够满足通常所有的路由需要。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值