Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [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.pce.pceservice; |
| 18 | |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 19 | import com.google.common.collect.Lists; |
| 20 | |
| 21 | import org.junit.After; |
| 22 | import org.junit.Before; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 23 | import org.junit.Test; |
| 24 | |
| 25 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | import static org.hamcrest.Matchers.is; |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 27 | import static org.onosproject.pce.pceservice.PathComputationTest.D2; |
| 28 | import static org.easymock.EasyMock.createMock; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 29 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 30 | import com.google.common.testing.EqualsTester; |
| 31 | |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 32 | |
| 33 | import org.onlab.osgi.ServiceDirectory; |
| 34 | import org.onlab.osgi.TestServiceDirectory; |
| 35 | import org.onlab.rest.BaseResource; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 36 | import org.onosproject.incubator.net.tunnel.TunnelId; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 37 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 38 | import org.onosproject.pce.pcestore.api.PceStore; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 39 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 40 | |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 41 | import java.util.List; |
| 42 | |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 43 | /** |
| 44 | * Unit tests for DefaultPcePath class. |
| 45 | */ |
| 46 | public class DefaultPcePathTest { |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 47 | private PceStore pceStore = createMock(PceStore.class); |
| 48 | |
| 49 | @Before |
| 50 | public void setup() { |
| 51 | |
| 52 | ServiceDirectory testDirectory = new TestServiceDirectory() |
| 53 | .add(PceStore.class, pceStore); |
| 54 | BaseResource.setServiceDirectory(testDirectory); |
| 55 | } |
| 56 | |
| 57 | @After |
| 58 | public void tearDownTest() { |
| 59 | } |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 60 | /** |
| 61 | * Checks the operation of equals() methods. |
| 62 | */ |
| 63 | @Test |
| 64 | public void testEquals() { |
| 65 | // create same two pce-path objects. |
| 66 | final String cost1 = "1"; |
| 67 | final String bandwidth1 = "200"; |
| 68 | final String src1 = "foo"; |
| 69 | final String dst1 = "bee"; |
| 70 | final String type1 = "1"; |
| 71 | final String name1 = "pcc"; |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 72 | final List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
| 73 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId()); |
| 74 | explicitPathInfoList.add(obj); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 75 | PcePath path1 = DefaultPcePath.builder() |
| 76 | .source(src1) |
| 77 | .destination(dst1) |
| 78 | .lspType(type1) |
| 79 | .name(name1) |
| 80 | .costConstraint(cost1) |
| 81 | .bandwidthConstraint(bandwidth1) |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 82 | .explicitPathInfo(explicitPathInfoList) |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 83 | .build(); |
| 84 | path1.id(TunnelId.valueOf("1")); |
| 85 | |
| 86 | // create same as above object |
| 87 | PcePath samePath1 = DefaultPcePath.builder() |
| 88 | .source(src1) |
| 89 | .destination(dst1) |
| 90 | .lspType(type1) |
| 91 | .name(name1) |
| 92 | .costConstraint(cost1) |
| 93 | .bandwidthConstraint(bandwidth1) |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 94 | .explicitPathInfo(explicitPathInfoList) |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 95 | .build(); |
| 96 | samePath1.id(TunnelId.valueOf("1")); |
| 97 | |
| 98 | // Create different pce-path object. |
| 99 | final String cost2 = "1"; |
| 100 | final String bandwidth2 = "200"; |
| 101 | final String src2 = "google"; |
| 102 | final String dst2 = "yahoo"; |
| 103 | final String type2 = "2"; |
| 104 | final String name2 = "pcc2"; |
| 105 | |
| 106 | PcePath path2 = DefaultPcePath.builder() |
| 107 | .source(src2) |
| 108 | .destination(dst2) |
| 109 | .lspType(type2) |
| 110 | .name(name2) |
| 111 | .costConstraint(cost2) |
| 112 | .bandwidthConstraint(bandwidth2) |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 113 | .explicitPathInfo(explicitPathInfoList) |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 114 | .build(); |
| 115 | path2.id(TunnelId.valueOf("2")); |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 116 | |
| 117 | new EqualsTester().addEqualityGroup(path1, samePath1).addEqualityGroup(path2).testEquals(); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Checks the construction of a DefaultPcePath object. |
| 122 | */ |
| 123 | @Test |
| 124 | public void testConstruction() { |
| 125 | final String cost = "1"; |
| 126 | final String bandwidth = "600"; |
| 127 | final String src = "indiatimes"; |
| 128 | final String dst = "deccan"; |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 129 | final String type = "2"; |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 130 | final String name = "pcc4"; |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 131 | final List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
| 132 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId()); |
| 133 | explicitPathInfoList.add(obj); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 134 | PcePath path = DefaultPcePath.builder() |
| 135 | .source(src) |
| 136 | .destination(dst) |
| 137 | .lspType(type) |
| 138 | .name(name) |
| 139 | .costConstraint(cost) |
| 140 | .bandwidthConstraint(bandwidth) |
Priyanka B | a32f6da | 2016-09-02 16:10:21 +0530 | [diff] [blame] | 141 | .explicitPathInfo(explicitPathInfoList) |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 142 | .build(); |
| 143 | |
Mahesh Poojary S | 3353620 | 2016-05-30 07:22:36 +0530 | [diff] [blame] | 144 | assertThat(path.source(), is(src)); |
| 145 | assertThat(path.destination(), is(dst)); |
| 146 | assertThat(path.lspType(), is(LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR)); |
| 147 | assertThat(path.name(), is(name)); |
| 148 | CostConstraint costConstExpected = CostConstraint.of(CostConstraint.Type.values()[Integer.valueOf(cost) - 1]); |
| 149 | CostConstraint costConstActual = (CostConstraint) path.costConstraint(); |
| 150 | assertThat(costConstActual.type(), is(costConstExpected.type())); |
| 151 | BandwidthConstraint bandwidthActual = (BandwidthConstraint) path.bandwidthConstraint(); |
| 152 | assertThat(bandwidthActual.bandwidth().bps(), is(Double.valueOf(bandwidth))); |
Mahesh Poojary S | d7a3692 | 2016-04-01 16:11:14 +0530 | [diff] [blame] | 153 | } |
| 154 | } |