Skip to content

Instantly share code, notes, and snippets.

Created Oct 31, 2020
What would you like to do?
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Build network-2
func Build() (host1 *link.Host, host2 *link.Host, host3 *link.Host,
swch1 *link.Switch, swch2 *link.Switch) {
// setup node
// setup interface
intf1 := link.NewInterface(40001, link.AddrFromStr("11-11-11-11-11-11"), host1)
attachInterface(host1, intf1)
intf2 := link.NewInterface(40002, link.AddrFromStr("22-22-22-22-22-22"), host2)
attachInterface(host2, intf2)
intf3 := link.NewInterface(40003, link.AddrFromStr("33-33-33-33-33-33"), host3)
attachInterface(host3, intf3)
sp11 := link.NewSwitchPort(40004, swch1)
sp12 := link.NewSwitchPort(40005, swch1)
sp13 := link.NewSwitchPort(40006, swch1)
attachSwchInterface(swch1, sp11, "1")
attachSwchInterface(swch1, sp12, "2")
attachSwchInterface(swch1, sp13, "3")
sp21 := link.NewSwitchPort(40007, swch2)
sp22 := link.NewSwitchPort(40008, swch2)
attachSwchInterface(swch2, sp21, "1")
attachSwchInterface(swch2, sp22, "2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment