Cleaned up the Rib class and renamed it to RibEntry
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
index 1825fed..1b55cd6 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
@@ -334,7 +334,7 @@
// Return nexthop address as byte array.
/*
- public Rib lookupRib(byte[] dest) {
+ public RibEntry lookupRib(byte[] dest) {
if (ptree == null) {
log.debug("lookupRib: ptree null");
return null;
@@ -470,7 +470,7 @@
}
//PtreeNode node = ptree.acquire(p.getAddress(), p.getPrefixLength());
- Rib rib = new Rib(router_id, nexthop, p.getPrefixLength());
+ RibEntry rib = new RibEntry(router_id, nexthop);
/*
if (node.rib != null) {
@@ -501,7 +501,7 @@
Prefix prefix = update.getPrefix();
//PtreeNode node = ptree.acquire(prefix.getAddress(), prefix.getPrefixLength());
- Rib rib = ptree.put(prefix, update.getRibEntry());
+ RibEntry rib = ptree.put(prefix, update.getRibEntry());
//if (node.rib != null) {
if (rib != null && !rib.equals(update.getRibEntry())) {
@@ -568,7 +568,7 @@
addPrefixFlows(prefix, node.rib);
}*/
- private void addPrefixFlows(Prefix prefix, Rib rib) {
+ private void addPrefixFlows(Prefix prefix, RibEntry rib) {
if (!topologyReady){
return;
}
@@ -578,16 +578,15 @@
//I think we'll have to make prefixAdded and prefixDelete atomic as well
//to protect against the prefix getting deleted while where trying to add it
- log.debug("New prefix {} added, next hop {}, routerId {}",
- new Object[] {prefix, rib.nextHop.getHostAddress(),
- rib.routerId.getHostAddress()});
+ log.debug("New prefix {} added, next hop {}",
+ prefix, rib.getNextHop().getHostAddress());
//TODO this is wrong, we shouldn't be dealing with BGP peers here.
//We need to figure out where the device is attached and what its
//mac address is by learning.
//The next hop is not necessarily the peer, and the peer's attachment
//point is not necessarily the next hop's attachment point.
- BgpPeer peer = bgpPeers.get(rib.nextHop);
+ BgpPeer peer = bgpPeers.get(rib.getNextHop());
if (peer == null){
//TODO local router isn't in peers list so this will get thrown
@@ -596,7 +595,7 @@
//The other scenario is this is a route server route. In that
//case the next hop is not in our configuration
log.error("Couldn't find next hop router in router {} in config",
- rib.nextHop.getHostAddress());
+ rib.getNextHop().getHostAddress());
return; //just quit out here? This is probably a configuration error
}
@@ -1042,10 +1041,10 @@
//addPrefixFlows(update.getPrefix(), update.getRibEntry());
//processRibAdd(update);
- Rib rib = ptree.lookup(update.getPrefix());
+ RibEntry rib = ptree.lookup(update.getPrefix());
if (rib != null && rib.equals(update.getRibEntry())) {
log.debug("Pushing prefix {} next hop {}", update.getPrefix(),
- rib.nextHop.getHostAddress());
+ rib.getNextHop().getHostAddress());
//We only push prefix flows if the prefix is still in the ptree
//and the next hop is the same as our update. The prefix could
//have been removed while we were waiting for the ARP, or the
@@ -1178,14 +1177,11 @@
@Override
public void topologyChanged() {
- //There seems to be more topology events than there should be. Lots of link
- //updated, port up and switch updated on what should be a fairly static topology
-
boolean refreshNeeded = false;
for (LDUpdate ldu : topology.getLastLinkUpdates()){
if (!ldu.getOperation().equals(ILinkDiscovery.UpdateOperation.LINK_UPDATED)){
//We don't need to recalculate anything for just link updates
- //They happen way too frequently (may be a bug in our link discovery)
+ //They happen very frequently
refreshNeeded = true;
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRouteResource.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRouteResource.java
index 2c9d284..c9b3265 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRouteResource.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRouteResource.java
@@ -147,7 +147,7 @@
return reply + "\n";
}
- Rib rib = new Rib(routerId, nexthop, p.getPrefixLength());
+ RibEntry rib = new RibEntry(routerId, nexthop);
bgpRoute.newRibUpdate(new RibUpdate(Operation.UPDATE, p, rib));
@@ -210,7 +210,7 @@
return reply + "\n";
}
- Rib r = new Rib(routerId, nextHop, p.getPrefixLength());
+ RibEntry r = new RibEntry(routerId, nextHop);
bgpRoute.newRibUpdate(new RibUpdate(Operation.DELETE, p, r));
@@ -242,7 +242,7 @@
else {
// clear the local rib: Ptree
bgpRoute.clearPtree();
- reply = "[DELE-capability: " + capability + "; The local Rib is cleared!]\n";
+ reply = "[DELE-capability: " + capability + "; The local RibEntry is cleared!]\n";
// to store the number in the top node of the Ptree
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/IBgpRouteService.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/IBgpRouteService.java
index b355c4b..ba912ce 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/IBgpRouteService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/IBgpRouteService.java
@@ -4,7 +4,7 @@
public interface IBgpRouteService extends IFloodlightService {
- //public Rib lookupRib(byte[] dest);
+ //public RibEntry lookupRib(byte[] dest);
//public Ptree getPtree();
public IPatriciaTrie getPtree();
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/IPatriciaTrie.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/IPatriciaTrie.java
index 9ec50bf..7fd7382 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/IPatriciaTrie.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/IPatriciaTrie.java
@@ -3,18 +3,18 @@
import java.util.Iterator;
public interface IPatriciaTrie {
- public Rib put(Prefix p, Rib r);
+ public RibEntry put(Prefix p, RibEntry r);
- public Rib lookup(Prefix p);
+ public RibEntry lookup(Prefix p);
- public Rib match(Prefix p);
+ public RibEntry match(Prefix p);
- public boolean remove(Prefix p, Rib r);
+ public boolean remove(Prefix p, RibEntry r);
public Iterator<Entry> iterator();
interface Entry {
public Prefix getPrefix();
- public Rib getRib();
+ public RibEntry getRib();
}
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/PatriciaTrie.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/PatriciaTrie.java
index 514758f..86bc8cf 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/PatriciaTrie.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/PatriciaTrie.java
@@ -15,7 +15,7 @@
this.maxPrefixLength = maxPrefixLength;
}
- public synchronized Rib put(Prefix p, Rib r) {
+ public synchronized RibEntry put(Prefix p, RibEntry r) {
if (p.getPrefixLength() > maxPrefixLength) {
throw new IllegalArgumentException(String.format(
"Prefix length %d is greater than max prefix length %d",
@@ -39,7 +39,7 @@
* case we are inserting a new nexthop for the prefix and should return
* the old nexthop.
*/
- Rib oldRib = node.rib;
+ RibEntry oldRib = node.rib;
node.rib = r;
return oldRib;
}
@@ -94,7 +94,7 @@
}
/*exact match*/
- public synchronized Rib lookup(Prefix p) {
+ public synchronized RibEntry lookup(Prefix p) {
//TODO
if (p.getPrefixLength() > maxPrefixLength) {
@@ -126,12 +126,12 @@
}
/*closest containing prefix*/
- public synchronized Rib match(Prefix p) {
+ public synchronized RibEntry match(Prefix p) {
//TODO
return null;
}
- public synchronized boolean remove(Prefix p, Rib r) {
+ public synchronized boolean remove(Prefix p, RibEntry r) {
Node child;
Node parent;
@@ -147,7 +147,7 @@
}
if (node.left != null && node.right != null) {
- //Remove the Rib entry and leave this node as an aggregate node
+ //Remove the RibEntry entry and leave this node as an aggregate node
//In the future, maybe we should re-evaluate what the aggregate prefix should be?
//It shouldn't necessarily stay the same.
//More complicated if the above prefix is also aggregate.
@@ -313,7 +313,7 @@
//Creating a new Prefix with a prefix length of common_len
//Bits are copied from node's up until the common_len'th bit
- //Rib is null, because this is an aggregate prefix - it's not
+ //RibEntry is null, because this is an aggregate prefix - it's not
//actually been added to the trie.
byte[] newPrefix = new byte[getByteContainingBit(maxPrefixLength)];
@@ -335,9 +335,9 @@
public Node right = null;
public Prefix prefix;
- public Rib rib;
+ public RibEntry rib;
- public Node(Prefix p, Rib r) {
+ public Node(Prefix p, RibEntry r) {
this.prefix = p;
this.rib = r;
}
@@ -349,9 +349,9 @@
private class PatriciaTrieEntry implements Entry {
private Prefix prefix;
- private Rib rib;
+ private RibEntry rib;
- public PatriciaTrieEntry(Prefix prefix, Rib rib) {
+ public PatriciaTrieEntry(Prefix prefix, RibEntry rib) {
this.prefix = prefix;
this.rib = rib;
}
@@ -362,7 +362,7 @@
}
@Override
- public Rib getRib() {
+ public RibEntry getRib() {
return rib;
}
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/PtreeNode.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/PtreeNode.java
index a4d6996..50b7c7d 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/PtreeNode.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/PtreeNode.java
@@ -13,7 +13,7 @@
public int refCount;
- public Rib rib;
+ public RibEntry rib;
protected static Logger log = LoggerFactory.getLogger(BgpRoute.class);
PtreeNode(byte [] key, int key_bits, int max_key_octet) {
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/Rib.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/Rib.java
deleted file mode 100644
index dc5f71d..0000000
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/Rib.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package net.onrc.onos.ofcontroller.bgproute;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-public class Rib {
- protected InetAddress routerId;
- protected InetAddress nextHop;
- protected int masklen;
-// protected int distance;
-
- Rib(InetAddress router_id, InetAddress nexthop, int masklen) {
- this.routerId = router_id;
- this.nextHop = nexthop;
- this.masklen = masklen;
-// this.distance = distance;
- }
-
- Rib(String router_id, String nexthop, int masklen) {
- try {
- this.routerId = InetAddress.getByName(router_id);
- } catch (UnknownHostException e) {
- System.out.println("InetAddress exception");
- }
- try {
- this.nextHop = InetAddress.getByName(nexthop);
- } catch (UnknownHostException e) {
- System.out.println("InetAddress exception");
- }
- this.masklen = masklen;
- }
-
- public InetAddress getNextHop() {
- return nextHop;
- }
-
- public int getMasklen(){
- return masklen;
- }
-
- public boolean equals(Rib r) {
-
- return this.routerId.equals(r.routerId) && this.nextHop.equals(r.nextHop) && this.masklen == r.masklen;
-
- }
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/RibEntry.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/RibEntry.java
new file mode 100644
index 0000000..c27f962
--- /dev/null
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/RibEntry.java
@@ -0,0 +1,47 @@
+package net.onrc.onos.ofcontroller.bgproute;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class RibEntry {
+ private InetAddress routerId;
+ private InetAddress nextHop;
+
+ public RibEntry(InetAddress routerId, InetAddress nextHop) {
+ this.routerId = routerId;
+ this.nextHop = nextHop;
+ }
+
+ public RibEntry(String routerId, String nextHop) {
+ try {
+ this.routerId = InetAddress.getByName(routerId);
+ this.nextHop = InetAddress.getByName(nextHop);
+ } catch (UnknownHostException e) {
+ throw new IllegalArgumentException("Invalid address format");
+ }
+ }
+
+ public InetAddress getNextHop() {
+ return nextHop;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == null || !(other instanceof RibEntry)) {
+ return false;
+ }
+
+ RibEntry otherRibEntry = (RibEntry) other;
+
+ return this.routerId.equals(otherRibEntry.routerId)
+ && this.nextHop.equals(otherRibEntry.nextHop);
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 17;
+ hash = 31 * hash + routerId.hashCode();
+ hash = 31 * hash + nextHop.hashCode();
+ return hash;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/RibUpdate.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/RibUpdate.java
index c7272bd..7d4d7a5 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/RibUpdate.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/RibUpdate.java
@@ -5,9 +5,9 @@
private Operation operation;
private Prefix prefix;
- private Rib ribEntry;
+ private RibEntry ribEntry;
- public RibUpdate(Operation operation, Prefix prefix, Rib ribEntry) {
+ public RibUpdate(Operation operation, Prefix prefix, RibEntry ribEntry) {
this.operation = operation;
this.prefix = prefix;
this.ribEntry = ribEntry;
@@ -21,7 +21,7 @@
return prefix;
}
- public Rib getRibEntry() {
+ public RibEntry getRibEntry() {
return ribEntry;
}
}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/bgproute/PatriciaTrieTest.java b/src/test/java/net/onrc/onos/ofcontroller/bgproute/PatriciaTrieTest.java
index d462d3e..1af0416 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/bgproute/PatriciaTrieTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/bgproute/PatriciaTrieTest.java
@@ -19,12 +19,12 @@
IPatriciaTrie ptrie;
Prefix[] prefixes;
- Map<Prefix, Rib> mappings;
+ Map<Prefix, RibEntry> mappings;
@Before
public void setUp() throws Exception {
ptrie = new PatriciaTrie(32);
- mappings = new HashMap<Prefix, Rib>();
+ mappings = new HashMap<Prefix, RibEntry>();
prefixes = new Prefix[] {
new Prefix("192.168.10.0", 24),
@@ -39,8 +39,8 @@
};
for (int i = 0; i < prefixes.length; i++) {
- mappings.put(prefixes[i], new Rib("192.168.10.101", "192.168.20." + i, 32));
- ptrie.put(prefixes[i], new Rib("192.168.10.101", "192.168.20." + i, 32));
+ mappings.put(prefixes[i], new RibEntry("192.168.10.101", "192.168.20." + i));
+ ptrie.put(prefixes[i], new RibEntry("192.168.10.101", "192.168.20." + i));
}
}
@@ -53,33 +53,33 @@
IPatriciaTrie ptrie = new PatriciaTrie(32);
Prefix p1 = new Prefix("192.168.240.0", 20);
- Rib r1 = new Rib("192.168.10.101", "192.168.60.2", 20);
- Rib retval = ptrie.put(p1, r1);
+ RibEntry r1 = new RibEntry("192.168.10.101", "192.168.60.2");
+ RibEntry retval = ptrie.put(p1, r1);
assertNull(retval);
retval = ptrie.lookup(p1);
assertTrue(r1 == retval); //should be the same object
Prefix p2 = new Prefix("192.160.0.0", 12);
- Rib r2 = new Rib("192.168.10.101", "192.168.20.1", 12);
+ RibEntry r2 = new RibEntry("192.168.10.101", "192.168.20.1");
retval = ptrie.put(p2, r2);
assertNull(retval);
Prefix p3 = new Prefix("192.168.208.0", 20);
- Rib r3 = new Rib("192.168.10.101", "192.168.30.1", 20);
+ RibEntry r3 = new RibEntry("192.168.10.101", "192.168.30.1");
retval = ptrie.put(p3, r3);
assertNull(retval);
- //Insert a new Rib entry over a previous one
- Rib r3new = new Rib("192.168.10.101", "192.168.60.2", 20);
+ //Insert a new RibEntry entry over a previous one
+ RibEntry r3new = new RibEntry("192.168.10.101", "192.168.60.2");
retval = ptrie.put(p3, r3new);
assertNotNull(retval);
assertTrue(retval.equals(r3));
assertTrue(retval == r3); //should be the same object
//Now we have an aggregate node with prefix 192.168.192.0/18.
- //We will insert a Rib at this prefix
+ //We will insert a RibEntry at this prefix
Prefix p4 = new Prefix("192.168.192.0", 18);
- Rib r4 = new Rib("192.168.10.101", "192.168.40.1", 18);
+ RibEntry r4 = new RibEntry("192.168.10.101", "192.168.40.1");
retval = ptrie.put(p4, r4);
assertNull(retval);
retval = ptrie.lookup(p4);
@@ -88,19 +88,19 @@
@Test
public void testLookup() {
- for (Map.Entry<Prefix, Rib> entry : mappings.entrySet()) {
- Rib r = ptrie.lookup(entry.getKey());
+ for (Map.Entry<Prefix, RibEntry> entry : mappings.entrySet()) {
+ RibEntry r = ptrie.lookup(entry.getKey());
assertTrue(entry.getValue().equals(r));
}
//These are aggregate nodes in the tree. Shouldn't be returned by lookup
Prefix p1 = new Prefix("0.0.0.0", 0);
- Rib retval = ptrie.lookup(p1);
+ RibEntry retval = ptrie.lookup(p1);
assertNull(retval);
- //We'll put a Rib at an aggregate node and check if lookup returns correctly
+ //We'll put a RibEntry at an aggregate node and check if lookup returns correctly
Prefix p2 = new Prefix("192.0.0.0", 4);
- Rib r2 = new Rib("192.168.10.101", "192.168.60.1", 4);
+ RibEntry r2 = new RibEntry("192.168.10.101", "192.168.60.1");
retval = ptrie.put(p2, r2);
assertNull(retval);
retval = ptrie.lookup(p2);
@@ -116,7 +116,7 @@
@Test
public void testRemove() {
Prefix p1 = new Prefix("192.168.8.0", 23);
- Rib retval = ptrie.lookup(p1);
+ RibEntry retval = ptrie.lookup(p1);
assertNotNull(retval);
boolean success = ptrie.remove(p1, retval);
assertTrue(success);
diff --git a/src/test/java/net/onrc/onos/ofcontroller/bgproute/PtreeTest.java b/src/test/java/net/onrc/onos/ofcontroller/bgproute/PtreeTest.java
index 1aa451c..6af9d30 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/bgproute/PtreeTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/bgproute/PtreeTest.java
@@ -53,9 +53,9 @@
byteAddresses.put(prefix, InetAddresses.forString(address).getAddress());
PtreeNode node = ptree.acquire(byteAddresses.get(prefix), prefixLength);
- node.rib = new Rib("192.168.10.101", "192.168.60.1", prefixLength);
+ node.rib = new RibEntry("192.168.10.101", "192.168.60.1");
ooptrie.put(new Prefix(byteAddresses.get(prefix), prefixLength),
- new Rib("192.168.10.101", "192.168.60.1", prefixLength));
+ new RibEntry("192.168.10.101", "192.168.60.1"));
}
}