Enhanced HostLocation and DefaultEdgeLink to allow easier construction.
Showing
3 changed files
with
39 additions
and
2 deletions
... | @@ -3,6 +3,7 @@ package org.onlab.onos.net; | ... | @@ -3,6 +3,7 @@ package org.onlab.onos.net; |
3 | import org.onlab.onos.net.provider.ProviderId; | 3 | import org.onlab.onos.net.provider.ProviderId; |
4 | 4 | ||
5 | import static com.google.common.base.Preconditions.checkArgument; | 5 | import static com.google.common.base.Preconditions.checkArgument; |
6 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
6 | 7 | ||
7 | /** | 8 | /** |
8 | * Default edge link model implementation. | 9 | * Default edge link model implementation. |
... | @@ -52,10 +53,14 @@ public class DefaultEdgeLink extends DefaultLink implements EdgeLink { | ... | @@ -52,10 +53,14 @@ public class DefaultEdgeLink extends DefaultLink implements EdgeLink { |
52 | * for network-to-host direction | 53 | * for network-to-host direction |
53 | * @return new phantom edge link | 54 | * @return new phantom edge link |
54 | */ | 55 | */ |
55 | - public static DefaultEdgeLink createEdgeLink(HostLocation edgePort, | 56 | + public static DefaultEdgeLink createEdgeLink(ConnectPoint edgePort, |
56 | boolean isIngress) { | 57 | boolean isIngress) { |
58 | + checkNotNull(edgePort, "Edge port cannot be null"); | ||
59 | + HostLocation location = (edgePort instanceof HostLocation) ? | ||
60 | + (HostLocation) edgePort : new HostLocation(edgePort, 0); | ||
57 | return new DefaultEdgeLink(ProviderId.NONE, | 61 | return new DefaultEdgeLink(ProviderId.NONE, |
58 | new ConnectPoint(HostId.NONE, PortNumber.P0), | 62 | new ConnectPoint(HostId.NONE, PortNumber.P0), |
59 | - edgePort, isIngress); | 63 | + location, isIngress); |
60 | } | 64 | } |
65 | + | ||
61 | } | 66 | } | ... | ... |
... | @@ -22,6 +22,17 @@ public class HostLocation extends ConnectPoint { | ... | @@ -22,6 +22,17 @@ public class HostLocation extends ConnectPoint { |
22 | } | 22 | } |
23 | 23 | ||
24 | /** | 24 | /** |
25 | + * Creates a new host location derived from the supplied connection point. | ||
26 | + * | ||
27 | + * @param connectPoint connection point | ||
28 | + * @param time time when detected, in millis since start of epoch | ||
29 | + */ | ||
30 | + public HostLocation(ConnectPoint connectPoint, long time) { | ||
31 | + super(connectPoint.deviceId(), connectPoint.port()); | ||
32 | + this.time = time; | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
25 | * Returns the time when the location was established, given in | 36 | * Returns the time when the location was established, given in |
26 | * milliseconds since start of epoch. | 37 | * milliseconds since start of epoch. |
27 | * | 38 | * | ... | ... |
... | @@ -5,6 +5,7 @@ import org.junit.Test; | ... | @@ -5,6 +5,7 @@ import org.junit.Test; |
5 | import org.onlab.onos.net.provider.ProviderId; | 5 | import org.onlab.onos.net.provider.ProviderId; |
6 | 6 | ||
7 | import static org.junit.Assert.assertEquals; | 7 | import static org.junit.Assert.assertEquals; |
8 | +import static org.onlab.onos.net.DefaultEdgeLink.createEdgeLink; | ||
8 | import static org.onlab.onos.net.DefaultLinkTest.cp; | 9 | import static org.onlab.onos.net.DefaultLinkTest.cp; |
9 | import static org.onlab.onos.net.DeviceId.deviceId; | 10 | import static org.onlab.onos.net.DeviceId.deviceId; |
10 | import static org.onlab.onos.net.HostId.hostId; | 11 | import static org.onlab.onos.net.HostId.hostId; |
... | @@ -55,4 +56,24 @@ public class DefaultEdgeLinkTest { | ... | @@ -55,4 +56,24 @@ public class DefaultEdgeLinkTest { |
55 | assertEquals("incorrect time", 123L, link.hostLocation().time()); | 56 | assertEquals("incorrect time", 123L, link.hostLocation().time()); |
56 | } | 57 | } |
57 | 58 | ||
59 | + @Test | ||
60 | + public void phantomIngress() { | ||
61 | + HostLocation hostLocation = new HostLocation(DID1, P1, 123L); | ||
62 | + EdgeLink link = createEdgeLink(hostLocation, true); | ||
63 | + assertEquals("incorrect dst", hostLocation, link.dst()); | ||
64 | + assertEquals("incorrect type", Link.Type.EDGE, link.type()); | ||
65 | + assertEquals("incorrect connect point", hostLocation, link.hostLocation()); | ||
66 | + assertEquals("incorrect time", 123L, link.hostLocation().time()); | ||
67 | + } | ||
68 | + | ||
69 | + @Test | ||
70 | + public void phantomEgress() { | ||
71 | + ConnectPoint hostLocation = new ConnectPoint(DID1, P1); | ||
72 | + EdgeLink link = createEdgeLink(hostLocation, false); | ||
73 | + assertEquals("incorrect src", hostLocation, link.src()); | ||
74 | + assertEquals("incorrect type", Link.Type.EDGE, link.type()); | ||
75 | + assertEquals("incorrect connect point", hostLocation, link.hostLocation()); | ||
76 | + assertEquals("incorrect time", 0L, link.hostLocation().time()); | ||
77 | + } | ||
78 | + | ||
58 | } | 79 | } | ... | ... |
-
Please register or login to post a comment