Coder Social home page Coder Social logo

exu's Introduction

exu ๐Ÿšž

A simple network emulation library for Go.

Example - Two PCs connected to a switch

sw1 := exu.NewVSwitch("sw1", 10)

disconnectFn := func(p *exu.VPort) {
    sw1.DisconnectPort(p)
}

connectFn := func(port *exu.VPort) {
    _ = sw1.ConnectToFirstAvailablePort(port)
}

go exu.NewRemoteVport(6554, net.ParseIP("10.0.0.1"), connectFn, disconnectFn)
go exu.NewRemoteVport(6555, net.ParseIP("10.0.0.2"), connectFn, disconnectFn)

select {}

On PC1

python3 -m http.server &
go run exu/client/main.go localhost 6554

On PC2

export pc1_ip="address of PC1"
go run exu/client/main.go $pc1_ip 6555

Now you can access http://10.0.0.1:8000 from PC2.

Example - One PC connected to a router

r1 := exu.NewVRouter("r1", 10)

r1 := exu.NewVRouter("r1", 10)
p1 := r1.GetFirstFreePort()
r1.SetPortIPNet(p1, net.IPNet{
    IP:   net.IPv4(10, 0, 0, 1),
    Mask: net.IPv4Mask(255, 255, 255, 0),
})

_, _ = exu.NewRemoteVport(6554, net.ParseIP("10.0.0.2"), func(port *exu.VPort) {
    _ = r1.ConnectPorts(p1, port)
}, func(p *exu.VPort) {
    log.Info("remote disconnected")
    r1.DisconnectPort(p1)
})

select {}

On PC1 you can run:

exu localhost 6554

And then ping the router:

ping -4 10.0.0.1

exu's People

Contributors

azer0s avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.