blob: 00ebedf3cb2e3d1f46cfb8ba2ceb7b4aaab217b7 [file] [log] [blame]
Ray Milkeydd5fb952015-02-25 17:00:28 -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 Milkeydd5fb952015-02-25 17:00:28 -080017
18import java.util.Collection;
19import java.util.List;
20import java.util.Set;
21
22import org.junit.Before;
23import org.junit.Test;
24import org.onosproject.net.DefaultLink;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.Link;
27import org.onosproject.net.flow.FlowRuleOperation;
28import org.onosproject.net.intent.LinkCollectionIntent;
29
30import com.google.common.collect.ImmutableSet;
31
32import static org.hamcrest.MatcherAssert.assertThat;
33import static org.hamcrest.Matchers.hasSize;
34import static org.hamcrest.Matchers.notNullValue;
35import static org.onosproject.net.Link.Type.DIRECT;
36import static org.onosproject.net.NetTestTools.APP_ID;
37import static org.onosproject.net.NetTestTools.PID;
38
39public class LinkCollectionIntentInstallerTest extends IntentInstallerTest {
40
41 LinkCollectionIntentInstaller installer;
42
43 private final Set<Link> links = ImmutableSet.of(
44 new DefaultLink(PID, d1p1, d2p0, DIRECT),
45 new DefaultLink(PID, d2p1, d3p1, DIRECT),
46 new DefaultLink(PID, d1p1, d3p1, DIRECT));
47
48 private LinkCollectionIntent intent;
49
50 /**
51 * Configures objects used in all the test cases.
52 */
53 @Before
54 public void localSetUp() {
55 installer = new LinkCollectionIntentInstaller();
56 installer.coreService = testCoreService;
57 installer.intentManager =
58 new IntentInstallerTest.MockIntentManager(LinkCollectionIntent.class);
Ray Milkeyebc5d222015-03-18 15:45:36 -070059 intent = LinkCollectionIntent.builder()
60 .appId(APP_ID)
61 .selector(selector)
62 .treatment(treatment)
63 .links(links)
64 .ingressPoints(ImmutableSet.of(d1p1))
65 .egressPoints(ImmutableSet.of(d3p1))
66 .build();
Ray Milkeydd5fb952015-02-25 17:00:28 -080067 }
68
69 private FlowRuleOperation findOperation(Collection<FlowRuleOperation> ops,
70 DeviceId deviceId) {
71 for (FlowRuleOperation op : ops) {
72 if (op.rule().deviceId().equals(deviceId)) {
73 return op;
74 }
75 }
76 return null;
77 }
78
79 /**
80 * Tests activation and deactivation of the installer.
81 */
82 @Test
83 public void activateDeactivate() {
84 installer.activate();
85 installer.deactivate();
86 }
87
88 /**
89 * Tests installation operation of the path intent installer.
90 */
91 @Test
92 public void install() {
93 installer.activate();
94
95 List<Collection<FlowRuleOperation>> operations =
96 installer.install(intent);
97 assertThat(operations, notNullValue());
98 assertThat(operations, hasSize(1));
99
100 Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
101 assertThat(flowRuleOpsCollection, hasSize(links.size()));
102
103 FlowRuleOperation op0 = findOperation(flowRuleOpsCollection,
104 d1p0.deviceId());
105 checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d1p0.deviceId());
106
107 FlowRuleOperation op1 = findOperation(flowRuleOpsCollection,
108 d2p0.deviceId());
109 checkFlowOperation(op1, FlowRuleOperation.Type.ADD, d2p0.deviceId());
110
111 FlowRuleOperation op2 = findOperation(flowRuleOpsCollection,
112 d3p0.deviceId());
113 checkFlowOperation(op2, FlowRuleOperation.Type.ADD, d3p0.deviceId());
114
115 installer.deactivate();
116 }
117
118 /**
119 * Checks the uninstall operation of the path intent installer.
120 */
121 @Test
122 public void uninstall() {
123 installer.activate();
124
125 List<Collection<FlowRuleOperation>> operations =
126 installer.uninstall(intent);
127 assertThat(operations, notNullValue());
128 assertThat(operations, hasSize(1));
129
130 Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0);
131 assertThat(flowRuleOpsCollection, hasSize(links.size()));
132
133 FlowRuleOperation op0 = findOperation(flowRuleOpsCollection,
134 d1p0.deviceId());
135 checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d1p0.deviceId());
136
137 FlowRuleOperation op1 = findOperation(flowRuleOpsCollection,
138 d2p0.deviceId());
139 checkFlowOperation(op1, FlowRuleOperation.Type.REMOVE, d2p0.deviceId());
140
141 FlowRuleOperation op2 = findOperation(flowRuleOpsCollection,
142 d3p0.deviceId());
143 checkFlowOperation(op2, FlowRuleOperation.Type.REMOVE, d3p0.deviceId());
144
145 installer.deactivate();
146 }
147}