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