blob: 8001eed7a5c71dab443f62371a03c9bf52641442 [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,
Ray Milkey50a9b722015-03-12 10:38:55 -070077 ImmutableList.of(),
78 55);
Ray Milkeybb320482015-02-25 15:16:46 -080079 }
80
81 /**
82 * Tests activation and deactivation of the installer.
83 */
84 @Test
85 public void activateDeactivate() {
86 installer.activate();
87 installer.deactivate();
88 }
89
90 /**
91 * Tests installation operation of the MPLS path intent installer.
92 */
93 @Test
94 public void install() {
95 installer.activate();
96
97 List<Collection<FlowRuleOperation>> operations =
98 installer.install(intent);
99 assertThat(operations, notNullValue());
100 assertThat(operations, hasSize(1));
101
102 Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
103 assertThat(flowRuleOpsCollection, hasSize(hops));
104 FlowRuleOperation[] flowRuleOps =
105 flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
106
107 FlowRuleOperation op0 = flowRuleOps[0];
108 checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d2p0.deviceId());
109
110 installer.deactivate();
111 }
112
113 /**
114 * Checks the uninstall operation of the path intent installer.
115 */
116 @Test
117 public void uninstall() {
118 installer.activate();
119
120 List<Collection<FlowRuleOperation>> operations =
121 installer.uninstall(intent);
122 assertThat(operations, notNullValue());
123 assertThat(operations, hasSize(1));
124
125 Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
126 assertThat(flowRuleOpsCollection, hasSize(hops));
127 FlowRuleOperation[] flowRuleOps =
128 flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]);
129
130 FlowRuleOperation op0 = flowRuleOps[0];
131 checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d2p0.deviceId());
132
133 installer.deactivate();
134 }
135}