blob: 904048543d277449b20ba7e9737e9779de332ba5 [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 Ba32f6da2016-09-02 16:10:21 +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 Ba32f6da2016-09-02 16:10:21 +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 Ba32f6da2016-09-02 16:10:21 +053032
33import org.onlab.osgi.ServiceDirectory;
34import org.onlab.osgi.TestServiceDirectory;
35import org.onlab.rest.BaseResource;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053036import org.onosproject.incubator.net.tunnel.TunnelId;
Mahesh Poojary S33536202016-05-30 07:22:36 +053037import org.onosproject.pce.pceservice.constraint.CostConstraint;
Priyanka Ba32f6da2016-09-02 16:10:21 +053038import org.onosproject.pce.pcestore.api.PceStore;
Mahesh Poojary S33536202016-05-30 07:22:36 +053039import org.onosproject.net.intent.constraint.BandwidthConstraint;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053040
Priyanka Ba32f6da2016-09-02 16:10:21 +053041import java.util.List;
42
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053043/**
44 * Unit tests for DefaultPcePath class.
45 */
46public class DefaultPcePathTest {
Priyanka Ba32f6da2016-09-02 16:10:21 +053047 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 Sd7a36922016-04-01 16:11:14 +053060 /**
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 Ba32f6da2016-09-02 16:10:21 +053072 final List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
73 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
74 explicitPathInfoList.add(obj);
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053075 PcePath path1 = DefaultPcePath.builder()
76 .source(src1)
77 .destination(dst1)
78 .lspType(type1)
79 .name(name1)
80 .costConstraint(cost1)
81 .bandwidthConstraint(bandwidth1)
Priyanka Ba32f6da2016-09-02 16:10:21 +053082 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053083 .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 Ba32f6da2016-09-02 16:10:21 +053094 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053095 .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 Ba32f6da2016-09-02 16:10:21 +0530113 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530114 .build();
115 path2.id(TunnelId.valueOf("2"));
Mahesh Poojary S33536202016-05-30 07:22:36 +0530116
117 new EqualsTester().addEqualityGroup(path1, samePath1).addEqualityGroup(path2).testEquals();
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530118 }
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 S33536202016-05-30 07:22:36 +0530129 final String type = "2";
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530130 final String name = "pcc4";
Priyanka Ba32f6da2016-09-02 16:10:21 +0530131 final List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
132 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
133 explicitPathInfoList.add(obj);
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530134 PcePath path = DefaultPcePath.builder()
135 .source(src)
136 .destination(dst)
137 .lspType(type)
138 .name(name)
139 .costConstraint(cost)
140 .bandwidthConstraint(bandwidth)
Priyanka Ba32f6da2016-09-02 16:10:21 +0530141 .explicitPathInfo(explicitPathInfoList)
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +0530142 .build();
143
Mahesh Poojary S33536202016-05-30 07:22:36 +0530144 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 Sd7a36922016-04-01 16:11:14 +0530153 }
154}