Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.net.intent; |
| 18 | |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 19 | import java.util.Collection; |
| 20 | import java.util.List; |
| 21 | |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 22 | import org.junit.Test; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.core.DefaultApplicationId; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 25 | import org.onosproject.net.DeviceId; |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 26 | import org.onosproject.net.NetworkResource; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 27 | import org.onosproject.net.ResourceGroup; |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 28 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 29 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 30 | import org.onosproject.net.flow.criteria.Criteria; |
| 31 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 32 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 33 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 34 | import org.onosproject.net.flowobjective.Objective; |
| 35 | |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 36 | import com.google.common.collect.ImmutableList; |
| 37 | import com.google.common.collect.ImmutableSet; |
| 38 | import com.google.common.testing.EqualsTester; |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 39 | |
| 40 | import static org.junit.Assert.assertEquals; |
| 41 | import static org.junit.Assert.assertTrue; |
| 42 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 43 | |
| 44 | /** |
| 45 | * Tests of the flow objective intent. |
| 46 | */ |
| 47 | public 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 Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 60 | private static final List<Objective> OBJECTIVES = ImmutableList.of(FO1, FO2); |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 61 | private static final Collection<NetworkResource> RESOURCES = ImmutableSet.of(); |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 62 | private static final List<DeviceId> DEVICE = ImmutableList.of(DeviceId.NONE, DeviceId.NONE); |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 63 | private static final ResourceGroup RESOURCE_GROUP = ResourceGroup.of(0L); |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Tests basics of construction and getters. |
| 67 | */ |
| 68 | @Test |
| 69 | public void basics() { |
| 70 | FlowObjectiveIntent intent = |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 71 | new FlowObjectiveIntent(APP_ID, KEY, DEVICE, OBJECTIVES, RESOURCES, RESOURCE_GROUP); |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 72 | 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 Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 76 | assertEquals("incorrect resource group", RESOURCE_GROUP, intent.resourceGroup()); |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 77 | 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 Milkey | 39f78b6 | 2018-01-05 15:17:37 -0800 | [diff] [blame] | 100 | return new FlowObjectiveIntent(APP_ID, null, DEVICE, OBJECTIVES, RESOURCES, null); |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
| 104 | protected Intent createAnother() { |
Ray Milkey | 39f78b6 | 2018-01-05 15:17:37 -0800 | [diff] [blame] | 105 | return new FlowObjectiveIntent(APP_ID, null, DEVICE, OBJECTIVES, RESOURCES, null); |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 106 | } |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 107 | } |