From 7bb2015a1f2de7a31c3f2b3092a574602a2a3d53 Mon Sep 17 00:00:00 2001 From: David Doan Date: Mon, 2 Oct 2023 19:22:21 -0400 Subject: initializations --- Makefile | 6 +++++ cmd/pkg/protocol.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ cmd/vhost/main.go | 17 ++++++++++++++ cmd/vrouter/main.go | 17 ++++++++++++++ go.mod | 3 +++ 5 files changed, 109 insertions(+) create mode 100644 Makefile create mode 100644 cmd/pkg/protocol.go create mode 100644 cmd/vhost/main.go create mode 100644 cmd/vrouter/main.go create mode 100644 go.mod diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f59715f --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +all: + go build -ldflags="-X 'main.Version=1.0.0'" -buildvcs=false ./cmd/vhost + go build -ldflags="-X 'main.Version=1.0.0'" -buildvcs=false ./cmd/vrouter + +clean: + rm -fv snowcast_control snowcast_server \ No newline at end of file diff --git a/cmd/pkg/protocol.go b/cmd/pkg/protocol.go new file mode 100644 index 0000000..84444c3 --- /dev/null +++ b/cmd/pkg/protocol.go @@ -0,0 +1,66 @@ +package pkg + +import ( + "net" + // "netip" +) + +const ( + MAX_IP_PACKET_SIZE = 1400 +) + +func Initialize(config IpConfig) (error) { + // ip config from go parser + + // initialize ip table + + // error check + + // different for router and host?? + // host + // create node interfaces? +} + +func ipRecv(data []byte) (error) { + // parse ip header + + // check ip checksum + + // check ip version + + // check ip length + + // check ip ttl + + // check ip protocol + + // check ip destination + + // check ip source + + // check forwarding table +} + +func ipForwarding(dst netip.Addr, protocolNum uint16, data []byte) (error) { + // send test packest to dst + + // lookup forwarding table + + // locally + + // not locally +} + +type HandlerFunc = func(*Packet, []interface{}) (error) { + + // do smth with packet +} + +func RegisterRecvHandler(protocolNum uint8, callbackFunc HandlerFunc) (error) { +} + +func routeRip() (error) { + // communicate with other routers + + // update forwarding table +} diff --git a/cmd/vhost/main.go b/cmd/vhost/main.go new file mode 100644 index 0000000..82b8195 --- /dev/null +++ b/cmd/vhost/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func main() { + + scanner := bufio.NewScanner(os.Stdin) + + for scanner.Scan() { + line := scanner.Text() + fmt.Println(line) + } +} \ No newline at end of file diff --git a/cmd/vrouter/main.go b/cmd/vrouter/main.go new file mode 100644 index 0000000..82b8195 --- /dev/null +++ b/cmd/vrouter/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func main() { + + scanner := bufio.NewScanner(os.Stdin) + + for scanner.Scan() { + line := scanner.Text() + fmt.Println(line) + } +} \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..032a459 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module golang-sockets + +go 1.18 \ No newline at end of file -- cgit v1.2.3-70-g09d2