blob: 9d95e4430ca71b812e7cef917480b5a4f4097846 [file] [log] [blame]
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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;
Mahesh Poojary S33536202016-05-30 07:22:36 +053020import com.google.common.testing.EqualsTester;
Ray Milkey094a1352018-01-22 14:03:54 -080021import org.junit.Test;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053022import org.onosproject.incubator.net.tunnel.TunnelId;
Mahesh Poojary S33536202016-05-30 07:22:36 +053023import org.onosproject.pce.pceservice.constraint.CostConstraint;
Satish K2eb5d842017-04-04 16:28:37 +053024import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053025import org.onosproject.pce.pcestore.api.PceStore;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053026
Priyanka Bbae0eeb12016-11-30 11:59:48 +053027import java.util.List;
28
Ray Milkey094a1352018-01-22 14:03:54 -080029import static org.easymock.EasyMock.createMock;
30import static org.hamcrest.MatcherAssert.assertThat;
31import static org.hamcrest.Matchers.is;
32import static org.onosproject.pce.pceservice.PathComputationTest.D2;
33
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053034/**
35 * Unit tests for DefaultPcePath class.
36 */
37public class DefaultPcePathTest {
Priyanka Bbae0eeb12016-11-30 11:59:48 +053038 private PceStore pceStore = createMock(PceStore.class);
39
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053040 /**
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 Bbae0eeb12016-11-30 11:59:48 +053052 final List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
53 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
54 explicitPathInfoList.add(obj);
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053055 PcePath path1 = DefaultPcePath.builder()
56 .source(src1)
57 .destination(dst1)
58 .lspType(type1)
59 .name(name1)
60 .costConstraint(cost1)
61 .bandwidthConstraint(bandwidth1)
Priyanka Bbae0eeb12016-11-30 11:59:48 +053062 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053063 .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 Bbae0eeb12016-11-30 11:59:48 +053074 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053075 .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 Bbae0eeb12016-11-30 11:59:48 +053093 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053094 .build();
95 path2.id(TunnelId.valueOf("2"));
Mahesh Poojary S33536202016-05-30 07:22:36 +053096
97 new EqualsTester().addEqualityGroup(path1, samePath1).addEqualityGroup(path2).testEquals();
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053098 }
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 S33536202016-05-30 07:22:36 +0530109 final String type = "2";
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530110 final String name = "pcc4";
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530111 final List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
112 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
113 explicitPathInfoList.add(obj);
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530114 PcePath path = DefaultPcePath.builder()
115 .source(src)
116 .destination(dst)
117 .lspType(type)
118 .name(name)
119 .costConstraint(cost)
120 .bandwidthConstraint(bandwidth)
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530121 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530122 .build();
123
Mahesh Poojary S33536202016-05-30 07:22:36 +0530124 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 K2eb5d842017-04-04 16:28:37 +0530131 PceBandwidthConstraint bandwidthActual = (PceBandwidthConstraint) path.bandwidthConstraint();
Mahesh Poojary S33536202016-05-30 07:22:36 +0530132 assertThat(bandwidthActual.bandwidth().bps(), is(Double.valueOf(bandwidth)));
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530133 }
134}