blob: ec3e334e902d79854b9d93330d09891035b931a1 [file] [log] [blame]
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -08001/*
2 * Copyright 2016 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 */
16
17package org.onosproject.net.intent;
18
19import com.google.common.collect.ImmutableSet;
20import com.google.common.testing.EqualsTester;
21import org.junit.Test;
22import org.onosproject.core.ApplicationId;
23import org.onosproject.core.DefaultApplicationId;
24import org.onosproject.net.NetworkResource;
25import org.onosproject.net.flow.DefaultTrafficSelector;
26import org.onosproject.net.flow.DefaultTrafficTreatment;
27import org.onosproject.net.flow.criteria.Criteria;
28import org.onosproject.net.flowobjective.DefaultFilteringObjective;
29import org.onosproject.net.flowobjective.DefaultForwardingObjective;
30import org.onosproject.net.flowobjective.ForwardingObjective;
31import org.onosproject.net.flowobjective.Objective;
32
33import java.util.Collection;
34
35import static org.junit.Assert.assertEquals;
36import static org.junit.Assert.assertTrue;
37import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
38
39/**
40 * Tests of the flow objective intent.
41 */
42public class FlowObjectiveIntentTest extends IntentTest {
43
44 private static final ApplicationId APP_ID = new DefaultApplicationId(1, "foo");
45 private static final Key KEY = Key.of("bar", APP_ID);
46
47 private static final Objective FO1 = DefaultFilteringObjective.builder()
48 .fromApp(APP_ID).addCondition(Criteria.matchEthType(123))
49 .permit().add();
50 private static final Objective FO2 = DefaultForwardingObjective.builder()
51 .fromApp(APP_ID)
52 .withSelector(DefaultTrafficSelector.builder().matchEthType((short) 123).build())
53 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
54 .withFlag(ForwardingObjective.Flag.VERSATILE).add();
55 private static final Collection<Objective> OBJECTIVES = ImmutableSet.of(FO1, FO2);
56 private static final Collection<NetworkResource> RESOURCES = ImmutableSet.of();
57
58 /**
59 * Tests basics of construction and getters.
60 */
61 @Test
62 public void basics() {
63 FlowObjectiveIntent intent =
64 new FlowObjectiveIntent(APP_ID, KEY, OBJECTIVES, RESOURCES);
65 assertEquals("incorrect app id", APP_ID, intent.appId());
66 assertEquals("incorrect key", KEY, intent.key());
67 assertEquals("incorrect objectives", OBJECTIVES, intent.objectives());
68 assertEquals("incorrect resources", RESOURCES, intent.resources());
69 assertTrue("should be installable", intent.isInstallable());
70 }
71
72 /**
73 * Tests equality.
74 */
75 @Test
76 public void equality() {
77 Intent a = createOne();
78 Intent b = createAnother();
79 new EqualsTester().addEqualityGroup(a).addEqualityGroup(b).testEquals();
80 }
81
82 /**
83 * Tests that instance is immutable.
84 */
85 @Test
86 public void testImmutability() {
87 assertThatClassIsImmutable(HostToHostIntent.class);
88 }
89
90 @Override
91 protected Intent createOne() {
92 return new FlowObjectiveIntent(APP_ID, OBJECTIVES, RESOURCES);
93 }
94
95 @Override
96 protected Intent createAnother() {
97 return new FlowObjectiveIntent(APP_ID, OBJECTIVES, RESOURCES);
98 }
99}