博主本人又来填坑了,协议配置有俩种方法,一种是Quagga(不再更新),另一个叫FRR。
Quagga很多年了,不说了,介绍一下FRR,
FRRouting(Free Range Routing)是一种开源的路由软件套件,它具有广泛的网络路由功能和灵活的可定制性。其主要功能是为计算机网络提供动态路由功能,使数据包能够在网络中选择最佳路径进行转发。FRRouting 可以应用于各种网络环境和场景,以下是 FRRouting 的一些常见应用场景:
- 企业网络: 提供动态路由协议(如 OSPF、BGP)来管理和优化网络流量。
2.数据中心网络: 在数据中心网络中,FRRouting 可以用于实现跨子网的灵活路由和负载均衡,支持各种网络拓扑结构和流量分布策略,以提供高性能和可扩展性。
3.广域网(WAN)互联: FRRouting 支持常用的广域网路由协议,例如 BGP(边界网关协议),允许不同地理位置的网络以可靠而高效的方式连接在一起。
问题:不支持mininet,支持py cmd控制
FRRouting :
https://frrouting.org/
我们这个项目用的是Quagga
Quagga的配置和安装很多了,我贴一个
https://blog.csdn.net/qq_39642794/article/details/102523670
mininet的代码,来自GitHub
#!/usr/bin/env python
import sys
from mininet.node import Controller, Host
from mininet.log import setLogLevel, info
from mn_wifi.cli import CLI
from mn_wifi.net import Mininet_wifi
from mininet.node import Switch
import sys
import os
import time
from time import sleep, time
from multiprocessing import Process
import sys
import os
import time
setLogLevel('info')
class Router(Switch):
"""Defines a new router that is inside a network namespace so that the
individual routing entries don't collide.
"""
ID = 0
def __init__(self, name, **kwargs):
kwargs['inNamespace'] = True
Switch.__init__(self, name, **kwargs)
Router.ID += 1
self.switch_id = Router.ID
@staticmethod
def setup():
return
def start(self, controllers):
pass
def stop(self):
self.deleteIntfs()
def SimpleTopo(net):
"Create a network."
num_hosts_per_router = 1
routers = []
hosts = []
c0 = net.addController('c0')
num_router = 5
for i in range(num_router):
router = net.addSwitch('r010_%d' % (i+1))
routers.append(router)
for i in range(num_router-1):
net.addLink('r010_%d' % (i+1), 'r010_%d' % (i+2))
net.addLink('r010_5', 'r010_1')
for i in range(num_router):
router = 'r010_%d' % (i+1)
for j in range(num_hosts_per_router):
hostname = 'h010_%d%d' % (i+1, j+1)
host = net.addHost(hostname)
hosts.append(host)
net.addLink(router, host)
#routers AS100 and AS200 and BGP links
router = net.addSwitch('r100_1')
routers.append(router)
router = net.addSwitch('r200_1')
routers.append(router)
net.addLink('r010_1', 'r100_1')
net.addLink('r010_1', 'r200_1')
net.addLink('r100_1', 'r200_1')
#AS100 hosts
router = 'r100_1'
for j in range(num_hosts_per_router):
hostname = 'h100_1%d' % (j+1)
host = net.addHost(hostname)
hosts.append(host)
net.addLink(router, host)
#AS200 hosts
router = 'r200_1'
for j in range(num_hosts_per_router):
hostname = 'h200_1%d' % (j+1)
host = net.addHost(hostname)
hosts.append(host)
net.addLink(router, host)
return net,c0
# Define host IP
def getIP(hostname):
if hostname == "h010_11":
ip = '10.1.0.2/24'
elif hostname == "h010_21":
ip = '10.2.0.2/24'
elif hostname == "h010_31":
ip = '10.3.0.2/24'
elif hostname == "h010_41":
ip = '10.4.0.2/24'
elif hostname == "h010_51":
ip = '10.5.0.2/24'
elif hostname == "h100_11":
ip = '100.1.0.2/24'
elif hostname == "h200_11":
ip = '200.1.0.2/24'
else:
ip = ''
return ip
# Define host Gateway
def getGateway(hostname):
if hostname == "h010_11":
gw = '10.1.0.1'
elif hostname == "h010_21":
gw = '10.2.0.1'
elif hostname == "h010_31":
gw = '10.3.0.1'
elif hostname == "h010_41":
gw = '10.4.0.1'
elif hostname == "h010_51":
gw = '10.5.0.1'
elif hostname == "h100_11":
gw = '100.1.0.1'
elif hostname == "h200_11":
gw = '200.1.0.1'
else:
gw = ''
return gw
# Start the routing daemons
# When a I2RS daemon is ready add it to the routers you want it to run, probably run:
# router.cmd("/usr/lib/quagga/i2rsd -f conf/i2rsd-%s.conf -d -i /tmp/i2rsd-%s.pid > logs/%s-i2rsd-stdout 2>&1" % (router.name, router.name, router.name))
# router.waitOutput()
def startRouting(router):
if router.name == "r010_1":
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/zebra/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))
router.waitOutput()
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/ospfd/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)
router.waitOutput()
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/bgpd/bgpd -f conf/bgpd-%s.conf -d -i /tmp/bgpd-%s.pid > logs/%s-bgpd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)
router.waitOutput()
elif router.name == "r010_2":
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/zebra/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))
router.waitOutput()
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/ospfd/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)
router.waitOutput()
elif router.name == "r010_3":
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/zebra/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))
router.waitOutput()
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/ospfd/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)
router.waitOutput()
elif router.name == "r010_4":
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/zebra/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))
router.waitOutput()
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/ospfd/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)
router.waitOutput()
elif router.name == "r010_5":
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/zebra/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))
router.waitOutput()
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/ospfd/ospfd -f conf/ospfd-%s.conf -d -i /tmp/ospfd-%s.pid > logs/%s-ospfd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)
router.waitOutput()
elif router.name == "r100_1":
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/zebra/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))
router.waitOutput()
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/bgpd/bgpd -f conf/bgpd-%s.conf -d -i /tmp/bgpd-%s.pid > logs/%s-bgpd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)
router.waitOutput()
elif router.name == "r200_1":
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/zebra/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))
router.waitOutput()
router.cmd("/home/ubuntu2308/Desktop/quagga-1.2.4/bgpd/bgpd -f conf/bgpd-%s.conf -d -i /tmp/bgpd-%s.pid > logs/%s-bgpd-stdout 2>&1" % (router.name, router.name, router.name), shell=True)
router.waitOutput()
return
def main():
os.system("rm -f /tmp/r*.log /tmp/r*.pid logs/*")
os.system("mn -c >/dev/null 2>&1")
os.system("killall -9 zebra bgpd ospfd > /dev/null 2>&1")
net = Mininet_wifi(controller=Controller, switch=Router)
net,c0 = SimpleTopo(net)
ap1 = net.addAccessPoint('ap1', ssid="ap1-ssid", mode="g",channel="1", position='30,30,0')
sta1 = net.addStation('sta1', ip="192.168.0.1/24", position='31,32,0')
#net.addLink(sta1, ap1)
info("*** Configuring Propagation Model\n")
net.setPropagationModel(model="logDistance", exp=4.5)
info("*** Configuring nodes\n")
net.configureNodes()
net. Build()
c0.start()
ap1.start([c0])
for router in net.switches:
router.cmd("sysctl -w net.ipv4.ip_forward=1")
router.waitOutput()
sleep(3)
for router in net.switches:
startRouting(router)
for host in net.hosts:
host.cmd("ifconfig %s-eth0 %s" % (host.name, getIP(host.name)))
host.cmd("route add default gw %s" % (getGateway(host.name)))
CLI(net)
net.stop()
os.system("killall -9 zebra bgpd ospfd")
if __name__ == "__main__":
main()
我们通过这个代码修改成自己的拓扑
配置文件大全
发现时延设置问题(解决)需要加上TClink:
验证路径和traceroute信息
修改后的网络拓扑如下