blob: 59fa89c09a090d90b99ef053961856f66e501cb9 [file] [log] [blame]
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05301/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05303 *
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
17package org.onosproject.pce.pceservice;
18
Priyanka Bbae0eeb12016-11-30 11:59:48 +053019import com.google.common.collect.Lists;
20
21import org.junit.After;
22import org.junit.Before;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053023import org.junit.Test;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053027import static org.onosproject.pce.pceservice.PathComputationTest.D2;
28import static org.easymock.EasyMock.createMock;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053029
Mahesh Poojary S33536202016-05-30 07:22:36 +053030import com.google.common.testing.EqualsTester;
31
Priyanka Bbae0eeb12016-11-30 11:59:48 +053032import org.onlab.osgi.ServiceDirectory;
33import org.onlab.osgi.TestServiceDirectory;
34import org.onlab.rest.BaseResource;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053035import org.onosproject.incubator.net.tunnel.TunnelId;
Mahesh Poojary S33536202016-05-30 07:22:36 +053036import org.onosproject.pce.pceservice.constraint.CostConstraint;
Satish K2eb5d842017-04-04 16:28:37 +053037import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053038import org.onosproject.pce.pcestore.api.PceStore;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053039
Priyanka Bbae0eeb12016-11-30 11:59:48 +053040import java.util.List;
41
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053042/**
43 * Unit tests for DefaultPcePath class.
44 */
45public class DefaultPcePathTest {
Priyanka Bbae0eeb12016-11-30 11:59:48 +053046 private PceStore pceStore = createMock(PceStore.class);
47
48 @Before
49 public void setup() {
50
51 ServiceDirectory testDirectory = new TestServiceDirectory()
52 .add(PceStore.class, pceStore);
53 BaseResource.setServiceDirectory(testDirectory);
54 }
55
56 @After
57 public void tearDownTest() {
58 }
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053059 /**
60 * Checks the operation of equals() methods.
61 */
62 @Test
63 public void testEquals() {
64 // create same two pce-path objects.
65 final String cost1 = "1";
66 final String bandwidth1 = "200";
67 final String src1 = "foo";
68 final String dst1 = "bee";
69 final String type1 = "1";
70 final String name1 = "pcc";
Priyanka Bbae0eeb12016-11-30 11:59:48 +053071 final List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
72 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
73 explicitPathInfoList.add(obj);
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053074 PcePath path1 = DefaultPcePath.builder()
75 .source(src1)
76 .destination(dst1)
77 .lspType(type1)
78 .name(name1)
79 .costConstraint(cost1)
80 .bandwidthConstraint(bandwidth1)
Priyanka Bbae0eeb12016-11-30 11:59:48 +053081 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053082 .build();
83 path1.id(TunnelId.valueOf("1"));
84
85 // create same as above object
86 PcePath samePath1 = DefaultPcePath.builder()
87 .source(src1)
88 .destination(dst1)
89 .lspType(type1)
90 .name(name1)
91 .costConstraint(cost1)
92 .bandwidthConstraint(bandwidth1)
Priyanka Bbae0eeb12016-11-30 11:59:48 +053093 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053094 .build();
95 samePath1.id(TunnelId.valueOf("1"));
96
97 // Create different pce-path object.
98 final String cost2 = "1";
99 final String bandwidth2 = "200";
100 final String src2 = "google";
101 final String dst2 = "yahoo";
102 final String type2 = "2";
103 final String name2 = "pcc2";
104
105 PcePath path2 = DefaultPcePath.builder()
106 .source(src2)
107 .destination(dst2)
108 .lspType(type2)
109 .name(name2)
110 .costConstraint(cost2)
111 .bandwidthConstraint(bandwidth2)
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530112 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530113 .build();
114 path2.id(TunnelId.valueOf("2"));
Mahesh Poojary S33536202016-05-30 07:22:36 +0530115
116 new EqualsTester().addEqualityGroup(path1, samePath1).addEqualityGroup(path2).testEquals();
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530117 }
118
119 /**
120 * Checks the construction of a DefaultPcePath object.
121 */
122 @Test
123 public void testConstruction() {
124 final String cost = "1";
125 final String bandwidth = "600";
126 final String src = "indiatimes";
127 final String dst = "deccan";
Mahesh Poojary S33536202016-05-30 07:22:36 +0530128 final String type = "2";
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530129 final String name = "pcc4";
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530130 final List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
131 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
132 explicitPathInfoList.add(obj);
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530133 PcePath path = DefaultPcePath.builder()
134 .source(src)
135 .destination(dst)
136 .lspType(type)
137 .name(name)
138 .costConstraint(cost)
139 .bandwidthConstraint(bandwidth)
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530140 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530141 .build();
142
Mahesh Poojary S33536202016-05-30 07:22:36 +0530143 assertThat(path.source(), is(src));
144 assertThat(path.destination(), is(dst));
145 assertThat(path.lspType(), is(LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR));
146 assertThat(path.name(), is(name));
147 CostConstraint costConstExpected = CostConstraint.of(CostConstraint.Type.values()[Integer.valueOf(cost) - 1]);
148 CostConstraint costConstActual = (CostConstraint) path.costConstraint();
149 assertThat(costConstActual.type(), is(costConstExpected.type()));
Satish K2eb5d842017-04-04 16:28:37 +0530150 PceBandwidthConstraint bandwidthActual = (PceBandwidthConstraint) path.bandwidthConstraint();
Mahesh Poojary S33536202016-05-30 07:22:36 +0530151 assertThat(bandwidthActual.bandwidth().bps(), is(Double.valueOf(bandwidth)));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530152 }
153}