首先说明一下我遇到的三个问题:
由于ipad网络不好图传不上就不传了,就是最终成型的图,加上一块左下角net-151(我本来设计的是有net0,net0下包含3个主机的,代码中有体现,但是跑不通,就暂时删了)
#!/usr/bin/env python3
# encoding: utf-8
from seedemu import *
# Create the Emulator
emu = Emulator()
# Create the base layer
base = Base()
###############################################################################
# Create Internet exchanges
ix110= base.createInternetExchange(110)
ix111 = base.createInternetExchange(111)
ix112 = base.createInternetExchange(112)
ix113 = base.createInternetExchange(113)
ix110.getPeeringLan().setDisplayName('Jiang Su-110')
ix111.getPeeringLan().setDisplayName('Shan Dong-111')
ix112.getPeeringLan().setDisplayName('Shan Xi-112')
ix113.getPeeringLan().setDisplayName('Shang Hai-113')
###############################################################################
# Create and set up a transit AS (AS-3)
as3 = base.createAutonomousSystem(3)
# Create 4 internal networks
as3.createNetwork('net0')
as3.createNetwork('net1')
as3.createNetwork('net2')
as3.createNetwork('net3')
# Create four routers and link them:
# r4 and r5 are BGP routers because they are connected to internet exchanges
as3.createRouter('r1').joinNetwork('net0').joinNetwork('net1')
as3.createRouter('r2').joinNetwork('net0').joinNetwork('net3')
as3.createRouter('r3').joinNetwork('net2').joinNetwork('net3')
as3.createRouter('r4').joinNetwork('net1').joinNetwork('net3').joinNetwork('ix113')
s3.createRouter('r5').joinNetwork('net0').joinNetwork('net2').joinNetwork('ix110')
###############################################################################
# Create and set up a transit AS (AS-5)
as5 = base.createAutonomousSystem(5)
# Create 1 internal networks
as5.createNetwork('net0')
# Create four routers and link them:
# r4 and r5 are BGP routers because they are connected to internet exchanges
as5.createRouter('r1').joinNetwork('net0').joinNetwork('ix110')
as5.createRouter('r2').joinNetwork('net0').joinNetwork('ix111')
###############################################################################
# Create and set up a transit AS (AS-4)
as4 = base.createAutonomousSystem(4)
# Create 1 internal networks
as4.createNetwork('net0')
# Create four routers and link them:
# r4 and r5 are BGP routers because they are connected to internet exchanges
as4.createRouter('r1').joinNetwork('net0').joinNetwork('ix112')
as4.createRouter('r2').joinNetwork('net0').joinNetwork('ix111')
###############################################################################
# Create and set up the stub AS (AS-178)
as178 = base.createAutonomousSystem(178)
# Create an internal network and a router
as178.createNetwork('net0')
as178.createRouter('router0').joinNetwork('net0').joinNetwork('ix110')
# Create two host nodes
as178.createHost('host0').joinNetwork('net0')
as178.createHost('host1').joinNetwork('net0', address = '10.178.0.81')
# Install additional software on a host
host0 = as178.getHost('host0')
host0.addSoftware('telnetd').addSoftware('telnet')
# Run an additional command inside the container
# The command creates a new account inside the host (also sets its password)
host0.addBuildCommand('useradd -m -s /bin/bash seed && echo "seed:dees" | chpasswd')
###############################################################################
# Create and set up the stub AS (AS-151)
as151 = base.createAutonomousSystem(151)
#as151.createNetwork('net0')
as151.createNetwork('net1')
as151.createRouter('router0').joinNetwork('net1').joinNetwork('ix112')#.joinNetwork('net0')
as151.createHost('host3').joinNetwork('net1')
as151.createHost('host4').joinNetwork('net1')
#as151.createHost('host0').joinNetwork('net0')
#as151.createHost('host1').joinNetwork('net0')
# Install additional software on a host
as151.getHost('host3').addSoftware('telnet')
###############################################################################
# BGP peering
# Create the Ebgp layer
ebgp = Ebgp()
# Make AS-3 the internet service provider for all the stub ASes
ebgp.addPrivatePeering (110, 3, 178, abRelationship = PeerRelationship.Provider)
ebgp.addPrivatePeerings(112, [4], [151], abRelationship = PeerRelationship.Provider)
# Peer AS-152 and AS-153 directly as peers
ebgp.addPrivatePeering(110, 3, 5, abRelationship = PeerRelationship.Peer)
ebgp.addPrivatePeering(111, 4, 5, abRelationship = PeerRelationship.Peer)
###############################################################################
# Web Service Layer
# Create the WebService layer
web = WebService()
# Create web service nodes (virtual nodes)
web.install('web01')
web.install('web02')
# Bind the virtual nodes to physical nodes
emu.addBinding(Binding('web01', filter = Filter(nodeName = 'host3', asn = 151)))
emu.addBinding(Binding('web02', filter = Filter(nodeName = 'host0', asn = 178)))
###############################################################################
emu.addLayer(base)
emu.addLayer(ebgp)
emu.addLayer(web)
emu.addLayer(Routing())
emu.addLayer(Ibgp())
emu.addLayer(Ospf())
###############################################################################
# Save it to a component file, so it can be used by other emulators
# This is optional
emu.dump('base-component.bin')
###############################################################################
# Rendering: This is where the actual binding happens
emu.render()
# Change the display name for the nodes hosting the web services
emu.getBindingFor('web01').setDisplayName('Web-1')
emu.getBindingFor('web02').setDisplayName('Web-2')
###############################################################################
# Compilation
# Generate the Docker files
emu.compile(Docker(), './output')
似乎是有一点奇怪的,配bgp估计存在着一定的问题
这一篇算是入门增强自信心的一篇,在改进之后会回来改善本文,尤其是上述3个问题亟待解答。
今天早上和晚上都些许搞了搞这玩意,下午八个小时是啥都没干,看小说看得乐在其中……
总之前几天定的进度今天差不多是完成了,明天需要实现自动化(先查一查是不是就是单纯print?),然后学习并完成bgp攻击。
又发现了一个问题,这个问题似乎能解决我提出的第三个问题
原来AS不止transit和stub,还有一个叫multihomed