Skip to content

Instantly share code, notes, and snippets.

@zeroFruit
Created October 31, 2020 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeroFruit/9d147190aa04337b6705f0a88f11b0f8 to your computer and use it in GitHub Desktop.
Save zeroFruit/9d147190aa04337b6705f0a88f11b0f8 to your computer and use it in GitHub Desktop.
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