Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58: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 | */ |
| 16 | |
| 17 | package org.onosproject.newoptical; |
| 18 | |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.util.Bandwidth; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.core.DefaultApplicationId; |
| 25 | import org.onosproject.core.IdGenerator; |
| 26 | import org.onosproject.net.CltSignalType; |
| 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.DeviceId; |
| 29 | import org.onosproject.net.OduSignalType; |
| 30 | import org.onosproject.net.PortNumber; |
| 31 | import org.onosproject.net.intent.Intent; |
| 32 | import org.onosproject.net.intent.Key; |
| 33 | import org.onosproject.net.intent.OpticalCircuitIntent; |
| 34 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 35 | |
| 36 | import static org.junit.Assert.*; |
| 37 | |
| 38 | /** |
| 39 | * Test class for PacketLinkRealizedByOptical class. |
| 40 | */ |
| 41 | public class PacketLinkRealizedByOpticalTest { |
| 42 | |
| 43 | private final ApplicationId appId = new DefaultApplicationId(0, "PacketLinkRealizedByOpticalTest"); |
| 44 | private IdGenerator idGenerator; |
| 45 | |
| 46 | @Before |
| 47 | public void setUp() { |
| 48 | idGenerator = new IdGenerator() { |
| 49 | int counter = 1; |
| 50 | |
| 51 | @Override |
| 52 | public long getNewId() { |
| 53 | return counter++; |
| 54 | } |
| 55 | }; |
| 56 | |
Thomas Vachuska | 2323596 | 2017-02-03 11:44:15 -0800 | [diff] [blame] | 57 | Intent.unbindIdGenerator(idGenerator); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 58 | Intent.bindIdGenerator(idGenerator); |
| 59 | } |
| 60 | |
| 61 | @After |
| 62 | public void tearDown() { |
| 63 | Intent.unbindIdGenerator(idGenerator); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Checks the construction of PacketLinkRealizedByOptical object with all parameters specified. |
| 68 | */ |
| 69 | @Test |
| 70 | public void testCreate() { |
| 71 | ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L)); |
| 72 | ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L)); |
| 73 | Key key = Key.of(10L, appId); |
| 74 | Bandwidth bandwidth = Bandwidth.bps(100L); |
| 75 | |
| 76 | PacketLinkRealizedByOptical plink = new PacketLinkRealizedByOptical(cp1, cp2, key, bandwidth); |
| 77 | |
| 78 | assertNotNull(plink); |
| 79 | assertEquals(plink.src(), cp1); |
| 80 | assertEquals(plink.dst(), cp2); |
| 81 | assertEquals((long) plink.bandwidth().bps(), 100L); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Checks the construction of OpticalConnectivityId object with OpticalCircuitIntent. |
| 86 | */ |
| 87 | @Test |
| 88 | public void testCreateWithCircuitIntent() { |
| 89 | ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L)); |
| 90 | ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L)); |
| 91 | OpticalCircuitIntent circuitIntent = OpticalCircuitIntent.builder() |
| 92 | .appId(appId) |
| 93 | .src(cp1) |
| 94 | .dst(cp2) |
| 95 | .bidirectional(true) |
| 96 | .key(Key.of(0, appId)) |
| 97 | .signalType(CltSignalType.CLT_1GBE) |
| 98 | .build(); |
| 99 | |
| 100 | PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, circuitIntent); |
| 101 | |
| 102 | assertNotNull(plink); |
| 103 | assertEquals(plink.src(), cp1); |
| 104 | assertEquals(plink.dst(), cp2); |
| 105 | assertEquals((long) plink.bandwidth().bps(), CltSignalType.CLT_1GBE.bitRate()); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Checks the construction of OpticalConnectivityId object with OpticalConnectivityIntent. |
| 110 | */ |
| 111 | @Test |
| 112 | public void testCreateWithConnectivityIntent() { |
| 113 | ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L)); |
| 114 | ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L)); |
| 115 | OpticalConnectivityIntent connIntent = OpticalConnectivityIntent.builder() |
| 116 | .appId(appId) |
| 117 | .src(cp1) |
| 118 | .dst(cp2) |
| 119 | .bidirectional(true) |
| 120 | .key(Key.of(0, appId)) |
| 121 | .signalType(OduSignalType.ODU4) |
| 122 | .build(); |
| 123 | |
| 124 | PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, connIntent); |
| 125 | |
| 126 | assertNotNull(plink); |
| 127 | assertEquals(plink.src(), cp1); |
| 128 | assertEquals(plink.dst(), cp2); |
| 129 | assertEquals((long) plink.bandwidth().bps(), OduSignalType.ODU4.bitRate()); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Checks that isBetween() method works. |
| 134 | */ |
| 135 | @Test |
| 136 | public void testIsBetween() { |
| 137 | ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L)); |
| 138 | ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L)); |
| 139 | ConnectPoint cp3 = new ConnectPoint(DeviceId.deviceId("of:0000000000000003"), PortNumber.portNumber(3L)); |
| 140 | OpticalCircuitIntent ochIntent = OpticalCircuitIntent.builder() |
| 141 | .appId(appId) |
| 142 | .src(cp1) |
| 143 | .dst(cp2) |
| 144 | .bidirectional(true) |
| 145 | .key(Key.of(0, appId)) |
| 146 | .signalType(CltSignalType.CLT_1GBE) |
| 147 | .build(); |
| 148 | |
| 149 | PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, ochIntent); |
| 150 | |
| 151 | assertTrue(plink.isBetween(cp1, cp2)); |
| 152 | assertFalse(plink.isBetween(cp1, cp3)); |
| 153 | } |
| 154 | } |