aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-10-23 01:48:23 -0400
committersotech117 <michael_foiani@brown.edu>2023-10-23 01:48:23 -0400
commit8f5877a04b3c82f5c298b87f6a0f6356d2acffcd (patch)
tree3e1a8b3e8d505ea917a3b0c2dc9f571ef617726b
parentdfb6e62b2484660730e271f5568d1366bd439864 (diff)
potentially implement reverse poision. fix port sending numbers. fix bug secing bug from router static routes.
-rw-r--r--cmd/vrouter/main.go2
-rw-r--r--loop/binaries.example.json23
-rw-r--r--loop/nodes.json9
-rw-r--r--pkg/ipstack/ipstack.go92
-rwxr-xr-xvhostbin3102340 -> 3105111 bytes
-rwxr-xr-xvrouterbin3102620 -> 3105159 bytes
6 files changed, 87 insertions, 39 deletions
diff --git a/cmd/vrouter/main.go b/cmd/vrouter/main.go
index f274741..aacf786 100644
--- a/cmd/vrouter/main.go
+++ b/cmd/vrouter/main.go
@@ -79,7 +79,7 @@ func main() {
myAddr := hop.Interface.IpPrefix.Addr()
for _, neighbor := range ipstack.GetNeighbors()[hop.Interface.Name] {
if neighbor.VipAddr == netip.MustParseAddr(ipAddr) ||
- neighbor.VipAddr == hop.VIP && hop.Type == "S" {
+ neighbor.VipAddr == hop.VIP {
err = ipstack.SendIP(&myAddr, neighbor, ipstack.TEST_PROTOCOL, messageToSendBytes, ipAddr, nil)
if err != nil {
fmt.Println(err)
diff --git a/loop/binaries.example.json b/loop/binaries.example.json
new file mode 100644
index 0000000..3d0d853
--- /dev/null
+++ b/loop/binaries.example.json
@@ -0,0 +1,23 @@
+{
+ "h1": {
+ "binary_path": "./vhost"
+ },
+ "h2": {
+ "binary_path": "./vhost"
+ },
+ "r1": {
+ "binary_path": "./vrouter"
+ },
+ "r2": {
+ "binary_path": "./vrouter"
+ },
+ "r3": {
+ "binary_path": "./vrouter"
+ },
+ "r4": {
+ "binary_path": "./vrouter"
+ },
+ "r5": {
+ "binary_path": "./vrouter"
+ }
+} \ No newline at end of file
diff --git a/loop/nodes.json b/loop/nodes.json
new file mode 100644
index 0000000..2829f76
--- /dev/null
+++ b/loop/nodes.json
@@ -0,0 +1,9 @@
+{
+ "h1": "host",
+ "h2": "host",
+ "r1": "router",
+ "r2": "router",
+ "r3": "router",
+ "r4": "router",
+ "r5": "router"
+} \ No newline at end of file
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go
index 7a5c235..9aaee28 100644
--- a/pkg/ipstack/ipstack.go
+++ b/pkg/ipstack/ipstack.go
@@ -337,26 +337,26 @@ func DebugNeighbors() {
}
}
-// TODO @ MICHAEL:
-// func RemoveNeighbor(neighbor Neighbor) {
-// // TODO: remove from routing table
-// myRoutes := GetRoutes()
-// for prefix, hop := range myRoutes {
-// if hop.VipAsStr == neighbor.VipAddr.String() {
-// delete(myRoutes, prefix)
-// }
-// }
-
-// // TODO: remove from myNeighbors
-// myNeighbors[neighbor.VipAddr.String()] = nil
-
-// // TODO: close the UDP socket
-// err := neighbor.SendSocket.Close()
-// if err != nil {
-// fmt.Println("Error closing UDP socket", err)
-// }
-
-// }
+//// TODO @ MICHAEL:
+//func RemoveNeighbor(neighbor Neighbor) {
+// // TODO: remove from routing table
+// myRoutes := GetRoutes()
+// for prefix, hop := range myRoutes {
+// if hop.VipAsStr == neighbor.VipAddr.String() {
+// delete(myRoutes, prefix)
+// }
+// }
+//
+// // TODO: remove from myNeighbors
+// myNeighbors[neighbor.VipAddr.String()] = nil
+//
+// // TODO: close the UDP socket
+// err := neighbor.SendSocket.Close()
+// if err != nil {
+// fmt.Println("Error closing UDP socket", err)
+// }
+//
+//}
// untested function above
// ************************************** BASIC FUNCTIONS **********************************************************
@@ -441,14 +441,19 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de
bytesToSend = append(bytesToSend, []byte(message)...)
sendAddr, err := net.ResolveUDPAddr("udp4", dest.UdpAddr.String())
- tmpConn, err := net.DialUDP("udp4", nil, sendAddr)
+ // tmpConn, err := net.DialUDP("udp4", nil, sendAddr)
+ // get the interface of this neighbor
if err != nil {
return errors.WithMessage(err, "Could not bind to UDP port->\t"+dest.UdpAddr.String())
}
- bytesWritten, err := tmpConn.Write(bytesToSend)
+ // bytesWritten, err := tmpConn.Write(bytesToSend)
+ // TODO: make this faster by removing call
+ iface, err := GetInterfaceByName(dest.Name)
+ bytesWritten, err := iface.RecvSocket.WriteToUDP(bytesToSend, sendAddr)
if err != nil {
- return err
+ fmt.Println("Error writing to UDP socket")
+ return errors.WithMessage(err, "Error writing to UDP socket")
}
fmt.Printf("Sent %d bytes to %s\n", bytesWritten, dest.VipAddr.String())
@@ -585,28 +590,36 @@ func RecvIP(iface *Interface, isOpen *bool) error {
func periodicUpdateRoutine() {
for {
// for each periodic update, we want to send our nodes in the table
- entries := make([]RIPEntry, len(routingTable))
- for prefix, hop := range routingTable {
- entries = append(entries,
- RIPEntry{
- address: ConvertIPToUint32(prefix.Addr().String()),
- mask: uint32(prefix.Bits()),
- cost: hop.Cost,
- })
- // fmt.Printf("Sending RIP update: %s\t%d\t%d\n", prefix.Addr().String(), uint32(prefix.Bits()), hop.Cost)
- }
-
- // send to each neighbor
for _, iface := range myInterfaces {
for _, n := range myNeighbors[iface.Name] {
_, in := myRIPNeighbors[n.VipAddr.String()]
if !in {
continue
}
+ // TODO: consider making this multithreaded and loops above more efficient
+
+ // if we're here, we are sending this to a rip neighbor
+ entries := make([]RIPEntry, len(routingTable))
+ for prefix, hop := range routingTable {
+ // implement split horizon + poison reverse at entry level
+ var cost uint32
+ if hop.VIP == n.VipAddr {
+ cost = INFINITY
+ } else {
+ cost = hop.Cost
+ }
+ entries = append(entries,
+ RIPEntry{
+ address: ConvertIPToUint32(prefix.Addr().String()),
+ mask: uint32(prefix.Bits()),
+ cost: cost,
+ })
+ }
+
message := NewRIPMessage(2, entries)
err := SendRIPMessage(*iface, n, message)
if err != nil {
- // fmt.Printf("Error sending RIP message to %s\n", n.VipAddr.String())
+ fmt.Printf("Error sending RIP message to %s\n", n.VipAddr.String())
continue
}
}
@@ -846,11 +859,14 @@ func SendRIPMessage(src Interface, dest *Neighbor, message *RIPMessage) error {
// send RIP message
sendAddr, err := net.ResolveUDPAddr("udp4", dest.UdpAddr.String())
- tmpConn, err := net.DialUDP("udp4", nil, sendAddr)
+ // tmpConn, err := net.DialUDP("udp4", nil, sendAddr)
if err != nil {
return errors.WithMessage(err, "Could not bind to UDP port->\t"+dest.UdpAddr.String())
}
- _, err = tmpConn.Write(bytesToSend)
+
+ iface, err := GetInterfaceByName(dest.Name)
+ //_, err = tmpConn.Write(bytesToSend)
+ _, err = iface.RecvSocket.WriteToUDP(bytesToSend, sendAddr)
if err != nil {
return err
}
diff --git a/vhost b/vhost
index fed5177..1c1151c 100755
--- a/vhost
+++ b/vhost
Binary files differ
diff --git a/vrouter b/vrouter
index 7799b95..7f788d0 100755
--- a/vrouter
+++ b/vrouter
Binary files differ