Carry more information in NextHop

Also update the next-hop CLI to show more information

Change-Id: Ia0f2c7b4a40b75513a4ecb4cc022e580e590d9f3
This commit is contained in:
Charles Chan 2016-11-09 16:52:11 -08:00 committed by Gerrit Code Review
parent 24f6cc01b1
commit c78a0987ef
3 changed files with 21 additions and 12 deletions

View File

@ -40,7 +40,7 @@ public class NextHopsListCommand extends AbstractShellCommand {
private static final String FORMAT_TABLE = "Table: %s";
private static final String FORMAT_TOTAL = " Total: %d";
private static final String FORMAT = "ip=%s, mac=%s, numRoutes=%s";
private static final String FORMAT = "ip=%s, mac=%s, loc=%s, numRoutes=%s";
@Override
protected void execute() {
@ -50,9 +50,8 @@ public class NextHopsListCommand extends AbstractShellCommand {
nextHops.forEach(nextHop -> {
Collection<Route> routes = service.getRoutesForNextHop(nextHop.ip());
print(FORMAT, nextHop.ip(), nextHop.mac(), routes.size());
print(FORMAT, nextHop.ip(), nextHop.mac(), nextHop.location(), routes.size());
});
}
}

View File

@ -18,6 +18,7 @@ package org.onosproject.incubator.net.routing;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.net.ConnectPoint;
import java.util.Objects;
@ -29,17 +30,17 @@ import static com.google.common.base.MoreObjects.toStringHelper;
public class NextHop {
private final IpAddress ip;
private final MacAddress mac;
private final NextHopData nextHopData;
/**
* Creates a new next hop.
*
* @param ip IP address
* @param mac MAC address
* @param nextHopData Next hop data
*/
public NextHop(IpAddress ip, MacAddress mac) {
public NextHop(IpAddress ip, NextHopData nextHopData) {
this.ip = ip;
this.mac = mac;
this.nextHopData = nextHopData;
}
/**
@ -57,12 +58,21 @@ public class NextHop {
* @return MAC address
*/
public MacAddress mac() {
return mac;
return nextHopData.mac();
}
/**
* Returns the location of the next hop.
*
* @return Connect point
*/
public ConnectPoint location() {
return nextHopData.location();
}
@Override
public int hashCode() {
return Objects.hash(ip, mac);
return Objects.hash(ip, nextHopData);
}
@Override
@ -78,14 +88,14 @@ public class NextHop {
NextHop that = (NextHop) other;
return Objects.equals(this.ip, that.ip) &&
Objects.equals(this.mac, that.mac);
Objects.equals(this.nextHopData, that.nextHopData);
}
@Override
public String toString() {
return toStringHelper(this)
.add("ip", ip)
.add("mac", mac)
.add("nextHopData", nextHopData)
.toString();
}
}

View File

@ -177,7 +177,7 @@ public class RouteManager implements ListenerService<RouteEvent, RouteListener>,
@Override
public Set<NextHop> getNextHops() {
return routeStore.getNextHops().entrySet().stream()
.map(entry -> new NextHop(entry.getKey(), entry.getValue().mac()))
.map(entry -> new NextHop(entry.getKey(), entry.getValue()))
.collect(Collectors.toSet());
}