blob: a0e635f502f8ebdfbb273a65a560f3a584a5eb32 [file] [log] [blame]
Ray Milkeybb320482015-02-25 15:16:46 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
Sho SHIMIZU3a7c98e2015-02-25 17:27:04 -080016package org.onosproject.net.intent.impl.installer;
Ray Milkeybb320482015-02-25 15:16:46 -080017
18import java.util.Arrays;
19import java.util.Collection;
20import java.util.List;
21import java.util.Optional;
22
23import org.junit.Before;
24import org.junit.Test;
25import org.onlab.packet.MplsLabel;
26import org.onosproject.net.DefaultLink;
27import org.onosproject.net.DefaultPath;
28import org.onosproject.net.Link;
29import org.onosproject.net.flow.FlowRuleOperation;
30import org.onosproject.net.intent.IntentTestsMocks;
31import org.onosproject.net.intent.MplsPathIntent;
32import org.onosproject.store.trivial.impl.SimpleLinkStore;
33
34import com.google.common.collect.ImmutableList;
35
36import static org.hamcrest.MatcherAssert.assertThat;
37import static org.hamcrest.Matchers.hasSize;
38import static org.hamcrest.Matchers.notNullValue;
39import static org.onosproject.net.Link.Type.DIRECT;
40import static org.onosproject.net.NetTestTools.APP_ID;
41import static org.onosproject.net.NetTestTools.PID;
42
43/**
44 * Unit tests for path intent installer.
45 */
46public class MplsPathIntentInstallerTest extends IntentInstallerTest {
47
48 MplsPathIntentInstaller installer;
49
50 private final Optional<MplsLabel> ingressLabel =
Ray Milkey167ae0b2015-02-26 07:33:25 -080051 Optional.of(MplsLabel.mplsLabel(10));
Ray Milkeybb320482015-02-25 15:16:46 -080052 private final Optional<MplsLabel> egressLabel =
Ray Milkey167ae0b2015-02-26 07:33:25 -080053 Optional.of(MplsLabel.mplsLabel(20));
Ray Milkeybb320482015-02-25 15:16:46 -080054
55 private final List<Link> links = Arrays.asList(
56 new DefaultLink(PID, d1p1, d2p0, DIRECT),
57 new DefaultLink(PID, d2p1, d3p1, DIRECT)
58 );
59 private final int hops = links.size() - 1;
60 private MplsPathIntent intent;
61
62 /**
63 * Configures objects used in all the test cases.
64 */
65 @Before
66 public void localSetUp() {
67 installer = new MplsPathIntentInstaller();
68 installer.coreService = testCoreService;
69 installer.intentManager = new MockIntentManager(MplsPathIntent.class);
70 installer.linkStore = new SimpleLinkStore();
71 installer.resourceService = new IntentTestsMocks.MockResourceService();
72
73 intent = new MplsPathIntent(APP_ID, selector, treatment,
74 new DefaultPath(PID, links, hops),
75 ingressLabel,
76 egressLabel,
77 ImmutableList.of());
78 }
79
80 /**
81 * Tests activation and deactivation of the installer.
82 */
83 @Test
84 public void activateDeactivate() {
85 installer.activate();
86 installer.deactivate();
87 }
88
89 /**
90 * Tests installation operation of the MPLS path intent installer.
91 */
92 @Test
93 public void install() {
94 installer.activate();
95
96 List<Collection<FlowRuleOperation>> operations =
97 installer.install(intent);
98 assertThat(operations, notNullValue());
99 assertThat(operations, hasSize(1));
100
101 Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
102 assertThat(flowRuleOpsCollection, hasSize(hops));
103 FlowRuleOperation[] flowRuleOps =
104 flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
105
106 FlowRuleOperation op0 = flowRuleOps[0];
107 checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d2p0.deviceId());
108
109 installer.deactivate();
110 }
111
112 /**
113 * Checks the uninstall operation of the path intent installer.
114 */
115 @Test
116 public void uninstall() {
117 installer.activate();
118
119 List<Collection<FlowRuleOperation>> operations =
120 installer.uninstall(intent);
121 assertThat(operations, notNullValue());
122 assertThat(operations, hasSize(1));
123
124 Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
125 assertThat(flowRuleOpsCollection, hasSize(hops));
126 FlowRuleOperation[] flowRuleOps =
127 flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
128
129 FlowRuleOperation op0 = flowRuleOps[0];
130 checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d2p0.deviceId());
131
132 installer.deactivate();
133 }
134}