Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 17 | |
| 18 | import org.junit.Test; |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.ConnectPoint; |
| 20 | import org.onosproject.net.FilteredConnectPoint; |
| 21 | |
| 22 | import java.util.HashSet; |
| 23 | import java.util.Set; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 24 | |
| 25 | import static org.junit.Assert.assertEquals; |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 26 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Suite of tests of the single-to-multi point intent descriptor. |
| 30 | */ |
| 31 | public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { |
| 32 | |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 33 | /** |
| 34 | * Checks that the SinglePointToMultiPointIntent class is immutable. |
| 35 | */ |
| 36 | @Test |
| 37 | public void testImmutability() { |
| 38 | assertThatClassIsImmutable(SinglePointToMultiPointIntent.class); |
| 39 | } |
| 40 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 41 | @Test |
| 42 | public void basics() { |
| 43 | SinglePointToMultiPointIntent intent = createOne(); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 44 | assertEquals("incorrect id", APPID, intent.appId()); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 45 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 46 | assertEquals("incorrect ingress", P1, intent.ingressPoint()); |
| 47 | assertEquals("incorrect egress", PS2, intent.egressPoints()); |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 48 | |
| 49 | intent = createAnother(); |
| 50 | assertEquals("incorrect id", APPID, intent.appId()); |
| 51 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 52 | assertEquals("incorrect ingress", P2, intent.ingressPoint()); |
| 53 | assertEquals("incorrect egress", PS1, intent.egressPoints()); |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 54 | |
| 55 | intent = createWithResourceGroup(); |
| 56 | assertEquals("incorrect id", APPID, intent.appId()); |
| 57 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 58 | assertEquals("incorrect ingress", P2, intent.ingressPoint()); |
| 59 | assertEquals("incorrect egress", PS1, intent.egressPoints()); |
| 60 | assertEquals("incorrect resource group", RESOURCE_GROUP, intent.resourceGroup()); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 63 | @Test |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 64 | public void filteredIntent() { |
| 65 | SinglePointToMultiPointIntent intent = createFilteredOne(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 66 | assertEquals("incorrect id", APPID, intent.appId()); |
| 67 | assertEquals("incorrect match", MATCH, intent.selector()); |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 68 | assertEquals("incorrect filtered ingress", FP2, intent.filteredIngressPoint()); |
| 69 | assertEquals("incorrect filtered egress", FPS1, intent.filteredEgressPoints()); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 70 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 71 | intent = createAnotherFiltered(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 72 | assertEquals("incorrect id", APPID, intent.appId()); |
| 73 | assertEquals("incorrect match", MATCH, intent.selector()); |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 74 | assertEquals("incorrect filtered ingress", FP1, intent.filteredIngressPoint()); |
| 75 | assertEquals("incorrect filtered egress", FPS2, intent.filteredEgressPoints()); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 78 | private Set<FilteredConnectPoint> filterPoints(Set<ConnectPoint> points) { |
| 79 | HashSet<FilteredConnectPoint> result = new HashSet<>(); |
| 80 | points.iterator().forEachRemaining(point -> result.add(new FilteredConnectPoint(point))); |
| 81 | return result; |
| 82 | } |
| 83 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 84 | @Override |
| 85 | protected SinglePointToMultiPointIntent createOne() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 86 | return SinglePointToMultiPointIntent.builder() |
| 87 | .appId(APPID) |
| 88 | .selector(MATCH) |
| 89 | .treatment(NOP) |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 90 | .filteredIngressPoint(new FilteredConnectPoint(P1)) |
| 91 | .filteredEgressPoints(filterPoints(PS2)) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 92 | .build(); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | protected SinglePointToMultiPointIntent createAnother() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 97 | return SinglePointToMultiPointIntent.builder() |
| 98 | .appId(APPID) |
| 99 | .selector(MATCH) |
| 100 | .treatment(NOP) |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 101 | .filteredIngressPoint(new FilteredConnectPoint(P2)) |
| 102 | .filteredEgressPoints(filterPoints(PS1)) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 103 | .build(); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 104 | } |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 105 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 106 | protected SinglePointToMultiPointIntent createWithResourceGroup() { |
| 107 | return SinglePointToMultiPointIntent.builder() |
| 108 | .appId(APPID) |
| 109 | .selector(MATCH) |
| 110 | .treatment(NOP) |
Ray Milkey | 4f7e363 | 2019-02-19 15:35:20 -0800 | [diff] [blame] | 111 | .filteredIngressPoint(new FilteredConnectPoint(P2)) |
| 112 | .filteredEgressPoints(filterPoints(PS1)) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 113 | .resourceGroup(RESOURCE_GROUP) |
| 114 | .build(); |
| 115 | } |
| 116 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 117 | protected SinglePointToMultiPointIntent createFilteredOne() { |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 118 | return SinglePointToMultiPointIntent.builder() |
| 119 | .appId(APPID) |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 120 | .treatment(NOP) |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 121 | .filteredEgressPoints(FPS1) |
| 122 | .filteredIngressPoint(FP2) |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 123 | .build(); |
| 124 | } |
| 125 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 126 | protected SinglePointToMultiPointIntent createAnotherFiltered() { |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 127 | return SinglePointToMultiPointIntent.builder() |
| 128 | .appId(APPID) |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 129 | .treatment(NOP) |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 130 | .filteredEgressPoints(FPS2) |
| 131 | .filteredIngressPoint(FP1) |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 132 | .build(); |
| 133 | } |
| 134 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 135 | protected SinglePointToMultiPointIntent createWrongIntent() { |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 136 | return SinglePointToMultiPointIntent.builder() |
| 137 | .appId(APPID) |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 138 | .treatment(NOP) |
| 139 | .selector(VLANMATCH1) |
| 140 | .filteredEgressPoints(FPS2) |
| 141 | .filteredIngressPoint(FP1) |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 142 | .build(); |
| 143 | } |
| 144 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 145 | } |