blob: 0b72e3402df24f8260826db860edea9c10732595 [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;
Luca Prete670ac5d2017-02-03 15:55:43 -080027import org.onosproject.net.ResourceGroup;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080028import org.onosproject.net.flow.DefaultTrafficSelector;
29import org.onosproject.net.flow.DefaultTrafficTreatment;
30import org.onosproject.net.flow.criteria.Criteria;
31import org.onosproject.net.flowobjective.DefaultFilteringObjective;
32import org.onosproject.net.flowobjective.DefaultForwardingObjective;
33import org.onosproject.net.flowobjective.ForwardingObjective;
34import org.onosproject.net.flowobjective.Objective;
35
Ray Milkey661c38c2016-02-26 17:12:17 -080036import com.google.common.collect.ImmutableList;
37import com.google.common.collect.ImmutableSet;
38import com.google.common.testing.EqualsTester;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080039
40import static org.junit.Assert.assertEquals;
41import static org.junit.Assert.assertTrue;
42import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
43
44/**
45 * Tests of the flow objective intent.
46 */
47public class FlowObjectiveIntentTest extends IntentTest {
48
49 private static final ApplicationId APP_ID = new DefaultApplicationId(1, "foo");
50 private static final Key KEY = Key.of("bar", APP_ID);
51
52 private static final Objective FO1 = DefaultFilteringObjective.builder()
53 .fromApp(APP_ID).addCondition(Criteria.matchEthType(123))
54 .permit().add();
55 private static final Objective FO2 = DefaultForwardingObjective.builder()
56 .fromApp(APP_ID)
57 .withSelector(DefaultTrafficSelector.builder().matchEthType((short) 123).build())
58 .withTreatment(DefaultTrafficTreatment.emptyTreatment())
59 .withFlag(ForwardingObjective.Flag.VERSATILE).add();
Ray Milkey661c38c2016-02-26 17:12:17 -080060 private static final List<Objective> OBJECTIVES = ImmutableList.of(FO1, FO2);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080061 private static final Collection<NetworkResource> RESOURCES = ImmutableSet.of();
Ray Milkey661c38c2016-02-26 17:12:17 -080062 private static final List<DeviceId> DEVICE = ImmutableList.of(DeviceId.NONE, DeviceId.NONE);
Luca Prete670ac5d2017-02-03 15:55:43 -080063 private static final ResourceGroup RESOURCE_GROUP = ResourceGroup.of(0L);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080064
65 /**
66 * Tests basics of construction and getters.
67 */
68 @Test
69 public void basics() {
70 FlowObjectiveIntent intent =
Luca Prete670ac5d2017-02-03 15:55:43 -080071 new FlowObjectiveIntent(APP_ID, KEY, DEVICE, OBJECTIVES, RESOURCES, RESOURCE_GROUP);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080072 assertEquals("incorrect app id", APP_ID, intent.appId());
73 assertEquals("incorrect key", KEY, intent.key());
74 assertEquals("incorrect objectives", OBJECTIVES, intent.objectives());
75 assertEquals("incorrect resources", RESOURCES, intent.resources());
Luca Prete670ac5d2017-02-03 15:55:43 -080076 assertEquals("incorrect resource group", RESOURCE_GROUP, intent.resourceGroup());
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080077 assertTrue("should be installable", intent.isInstallable());
78 }
79
80 /**
81 * Tests equality.
82 */
83 @Test
84 public void equality() {
85 Intent a = createOne();
86 Intent b = createAnother();
87 new EqualsTester().addEqualityGroup(a).addEqualityGroup(b).testEquals();
88 }
89
90 /**
91 * Tests that instance is immutable.
92 */
93 @Test
94 public void testImmutability() {
95 assertThatClassIsImmutable(HostToHostIntent.class);
96 }
97
98 @Override
99 protected Intent createOne() {
Ray Milkey661c38c2016-02-26 17:12:17 -0800100 return new FlowObjectiveIntent(APP_ID, DEVICE, OBJECTIVES, RESOURCES);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -0800101 }
102
103 @Override
104 protected Intent createAnother() {
Ray Milkey661c38c2016-02-26 17:12:17 -0800105 return new FlowObjectiveIntent(APP_ID, DEVICE, OBJECTIVES, RESOURCES);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -0800106 }
Ray Milkey661c38c2016-02-26 17:12:17 -0800107}