aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDavid Doan <daviddoan@Davids-MacBook-Pro-70.local>2023-10-05 23:32:06 -0400
committerDavid Doan <daviddoan@Davids-MacBook-Pro-70.local>2023-10-05 23:32:06 -0400
commit770a08b747233942fb19da529763f61987a804d6 (patch)
tree3c822fde32750780fe38f46b6f25e9642c1cec0f /cmd
parent7bb2015a1f2de7a31c3f2b3092a574602a2a3d53 (diff)
file importing
Diffstat (limited to 'cmd')
-rw-r--r--cmd/pkg/protocol.go66
-rw-r--r--cmd/vrouter/main.go28
2 files changed, 28 insertions, 66 deletions
diff --git a/cmd/pkg/protocol.go b/cmd/pkg/protocol.go
deleted file mode 100644
index 84444c3..0000000
--- a/cmd/pkg/protocol.go
+++ /dev/null
@@ -1,66 +0,0 @@
-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/vrouter/main.go b/cmd/vrouter/main.go
index 82b8195..158016a 100644
--- a/cmd/vrouter/main.go
+++ b/cmd/vrouter/main.go
@@ -4,9 +4,37 @@ import (
"bufio"
"fmt"
"os"
+ "time"
)
+func SendUpdates() {
+ for _, iface := range myInterfaces {
+ // send RIP updates to all neighbors
+ for _, neighbor := range myNeighbors {
+ iface.udp.Write(neighbor, data)
+ // wait for response for 12 seconds
+ response := make([]byte, 512)
+ iface.udp.Read(response)
+ time.Sleep(12 * time.Second)
+ if len(response) == 0 {
+ RemoveNeighbor(neighbor)
+ }
+ }
+ }
+ time.Sleep(5 * time.Second)
+}
+
func main() {
+ if len(os.Args) != 2 {
+ fmt.Printf("Usage: %s <configFile>\n", os.Args[0])
+ os.Exit(1)
+ }
+
+ fileName := os.Args[1]
+
+ initialize(fileName)
+ go SendUpdates()
+
scanner := bufio.NewScanner(os.Stdin)