blob: 69418a90cc7dac9458f258563a92b75a653c73a1 [file] [log] [blame]
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -08003 *
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
Ray Milkey661c38c2016-02-26 17:12:17 -080019import java.util.Collection;
20import java.util.List;
21
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080022import org.junit.Test;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.core.DefaultApplicationId;
Ray Milkey661c38c2016-02-26 17:12:17 -080025import org.onosproject.net.DeviceId;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080026import org.onosproject.net.NetworkResource;
27import org.onosproject.net.flow.DefaultTrafficSelector;
28import org.onosproject.net.flow.DefaultTrafficTreatment;
29import org.onosproject.net.flow.criteria.Criteria;
30import org.onosproject.net.flowobjective.DefaultFilteringObjective;
31import org.onosproject.net.flowobjective.DefaultForwardingObjective;
32import org.onosproject.net.flowobjective.ForwardingObjective;
33import org.onosproject.net.flowobjective.Objective;
34
Ray Milkey661c38c2016-02-26 17:12:17 -080035import com.google.common.collect.ImmutableList;
36import com.google.common.collect.ImmutableSet;
37import com.google.common.testing.EqualsTester;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080038
39import static org.junit.Assert.assertEquals;
40import static org.junit.Assert.assertTrue;
41import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
42
43/**
44 * Tests of the flow objective intent.
45 */
46public class FlowObjectiveIntentTest extends IntentTest {
47
48 private static final ApplicationId APP_ID = new DefaultApplicationId(1, "foo");
49 private static final Key KEY = Key.of("bar", APP_ID);
50
51 private static final Objective FO1 = DefaultFilteringObjective.builder()
52 .fromApp(APP_ID).addCondition(Criteria.matchEthType(123))
53 .permit().add();
54 private static final Objective FO2 = DefaultForwardingObjective.builder()
55 .fromApp(APP_ID)
56 .withSelector(DefaultTrafficSelector.builder().matchEthType((short) 123).build())
57 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
58 .withFlag(ForwardingObjective.Flag.VERSATILE).add();
Ray Milkey661c38c2016-02-26 17:12:17 -080059 private static final List<Objective> OBJECTIVES = ImmutableList.of(FO1, FO2);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080060 private static final Collection<NetworkResource> RESOURCES = ImmutableSet.of();
Ray Milkey661c38c2016-02-26 17:12:17 -080061 private static final List<DeviceId> DEVICE = ImmutableList.of(DeviceId.NONE, DeviceId.NONE);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080062
63 /**
64 * Tests basics of construction and getters.
65 */
66 @Test
67 public void basics() {
68 FlowObjectiveIntent intent =
Ray Milkey661c38c2016-02-26 17:12:17 -080069 new FlowObjectiveIntent(APP_ID, KEY, DEVICE, OBJECTIVES, RESOURCES);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080070 assertEquals("incorrect app id", APP_ID, intent.appId());
71 assertEquals("incorrect key", KEY, intent.key());
72 assertEquals("incorrect objectives", OBJECTIVES, intent.objectives());
73 assertEquals("incorrect resources", RESOURCES, intent.resources());
74 assertTrue("should be installable", intent.isInstallable());
75 }
76
77 /**
78 * Tests equality.
79 */
80 @Test
81 public void equality() {
82 Intent a = createOne();
83 Intent b = createAnother();
84 new EqualsTester().addEqualityGroup(a).addEqualityGroup(b).testEquals();
85 }
86
87 /**
88 * Tests that instance is immutable.
89 */
90 @Test
91 public void testImmutability() {
92 assertThatClassIsImmutable(HostToHostIntent.class);
93 }
94
95 @Override
96 protected Intent createOne() {
Ray Milkey661c38c2016-02-26 17:12:17 -080097 return new FlowObjectiveIntent(APP_ID, DEVICE, OBJECTIVES, RESOURCES);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080098 }
99
100 @Override
101 protected Intent createAnother() {
Ray Milkey661c38c2016-02-26 17:12:17 -0800102 return new FlowObjectiveIntent(APP_ID, DEVICE, OBJECTIVES, RESOURCES);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -0800103 }
Ray Milkey661c38c2016-02-26 17:12:17 -0800104}