Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.provider.ProviderId; |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 21 | |
| 22 | import static org.junit.Assert.assertEquals; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import static org.onosproject.net.DefaultEdgeLink.createEdgeLink; |
| 24 | import static org.onosproject.net.DefaultLinkTest.cp; |
| 25 | import static org.onosproject.net.DeviceId.deviceId; |
| 26 | import static org.onosproject.net.HostId.hostId; |
| 27 | import static org.onosproject.net.PortNumber.portNumber; |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Test of the default edge link model entity. |
| 31 | */ |
| 32 | public class DefaultEdgeLinkTest { |
| 33 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 34 | private static final ProviderId PID = new ProviderId("of", "foo"); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 35 | private static final DeviceId DID1 = deviceId("of:foo"); |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 36 | private static final HostId HID1 = hostId("00:00:00:00:00:01/-1"); |
| 37 | private static final HostId HID2 = hostId("00:00:00:00:00:01/-1"); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 38 | private static final PortNumber P0 = portNumber(0); |
| 39 | private static final PortNumber P1 = portNumber(1); |
| 40 | |
| 41 | @Test |
| 42 | public void testEquality() { |
| 43 | EdgeLink l1 = new DefaultEdgeLink(PID, cp(HID1, P0), |
| 44 | new HostLocation(DID1, P1, 123L), true); |
| 45 | EdgeLink l2 = new DefaultEdgeLink(PID, cp(HID1, P0), |
| 46 | new HostLocation(DID1, P1, 123L), true); |
| 47 | |
| 48 | EdgeLink l3 = new DefaultEdgeLink(PID, cp(HID2, P0), |
| 49 | new HostLocation(DID1, P1, 123L), false); |
| 50 | EdgeLink l4 = new DefaultEdgeLink(PID, cp(HID2, P0), |
| 51 | new HostLocation(DID1, P1, 123L), false); |
| 52 | |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 53 | new EqualsTester().addEqualityGroup(l1, l2) |
| 54 | .addEqualityGroup(l3, l4) |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 55 | .testEquals(); |
| 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void basics() { |
| 60 | HostLocation hostLocation = new HostLocation(DID1, P1, 123L); |
| 61 | EdgeLink link = new DefaultEdgeLink(PID, cp(HID1, P0), hostLocation, false); |
tom | cbefa23 | 2014-09-16 14:17:20 -0700 | [diff] [blame] | 62 | assertEquals("incorrect src", cp(HID1, P0), link.dst()); |
| 63 | assertEquals("incorrect dst", hostLocation, link.src()); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 64 | assertEquals("incorrect type", Link.Type.EDGE, link.type()); |
| 65 | assertEquals("incorrect hostId", HID1, link.hostId()); |
| 66 | assertEquals("incorrect connect point", hostLocation, link.hostLocation()); |
| 67 | assertEquals("incorrect time", 123L, link.hostLocation().time()); |
| 68 | } |
| 69 | |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 70 | @Test |
| 71 | public void phantomIngress() { |
| 72 | HostLocation hostLocation = new HostLocation(DID1, P1, 123L); |
| 73 | EdgeLink link = createEdgeLink(hostLocation, true); |
| 74 | assertEquals("incorrect dst", hostLocation, link.dst()); |
| 75 | assertEquals("incorrect type", Link.Type.EDGE, link.type()); |
| 76 | assertEquals("incorrect connect point", hostLocation, link.hostLocation()); |
| 77 | assertEquals("incorrect time", 123L, link.hostLocation().time()); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void phantomEgress() { |
| 82 | ConnectPoint hostLocation = new ConnectPoint(DID1, P1); |
| 83 | EdgeLink link = createEdgeLink(hostLocation, false); |
| 84 | assertEquals("incorrect src", hostLocation, link.src()); |
| 85 | assertEquals("incorrect type", Link.Type.EDGE, link.type()); |
| 86 | assertEquals("incorrect connect point", hostLocation, link.hostLocation()); |
| 87 | assertEquals("incorrect time", 0L, link.hostLocation().time()); |
| 88 | } |
| 89 | |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 90 | } |