Skip to content

Instantly share code, notes, and snippets.

@zeroFruit
Created October 31, 2020 12:19
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/7ef06d758c9a7ade529bde047dfb02ec to your computer and use it in GitHub Desktop.
Save zeroFruit/7ef06d758c9a7ade529bde047dfb02ec to your computer and use it in GitHub Desktop.
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Network Topology
package link
type Link struct {
cost uint
ep1 EndPoint
ep2 EndPoint
}
func (l *Link) AttachEndpoint(ep EndPoint) error {
...
}
// Opposite returns other endpoint of given id. If other endpoint does not exist,
// then return error
func (l *Link) Opposite(id Id) (EndPoint, error) {
...
}
// EndPoint represents point of link. Link is the channel to pass data to end-point
// either side to the opposite
type EndPoint interface {
Id() Id
GetLink() *Link
AttachLink(link *Link) error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment