blob: 12d8bccb37fcac99cdf4c35ee38757a37427074e [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorf3d06162014-10-02 15:54:12 -070017
18import org.junit.Test;
Ray Milkey4f7e3632019-02-19 15:35:20 -080019import org.onosproject.net.ConnectPoint;
20import org.onosproject.net.FilteredConnectPoint;
21
22import java.util.HashSet;
23import java.util.Set;
Brian O'Connorf3d06162014-10-02 15:54:12 -070024
25import static org.junit.Assert.assertEquals;
Ray Milkeybd4f0112015-03-02 17:07:09 -080026import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Brian O'Connorf3d06162014-10-02 15:54:12 -070027
28/**
29 * Suite of tests of the single-to-multi point intent descriptor.
30 */
31public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest {
32
Ray Milkeybd4f0112015-03-02 17:07:09 -080033 /**
34 * Checks that the SinglePointToMultiPointIntent class is immutable.
35 */
36 @Test
37 public void testImmutability() {
38 assertThatClassIsImmutable(SinglePointToMultiPointIntent.class);
39 }
40
Brian O'Connorf3d06162014-10-02 15:54:12 -070041 @Test
42 public void basics() {
43 SinglePointToMultiPointIntent intent = createOne();
Thomas Vachuskac96058a2014-10-20 23:00:16 -070044 assertEquals("incorrect id", APPID, intent.appId());
tom85258ee2014-10-07 00:10:02 -070045 assertEquals("incorrect match", MATCH, intent.selector());
46 assertEquals("incorrect ingress", P1, intent.ingressPoint());
47 assertEquals("incorrect egress", PS2, intent.egressPoints());
Yi Tseng2a81c9d2016-09-14 10:14:24 -070048
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 Prete670ac5d2017-02-03 15:55:43 -080054
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'Connorf3d06162014-10-02 15:54:12 -070061 }
62
Pier Ventre27d42572016-08-29 17:37:08 -070063 @Test
Yi Tseng2a81c9d2016-09-14 10:14:24 -070064 public void filteredIntent() {
65 SinglePointToMultiPointIntent intent = createFilteredOne();
Pier Ventre27d42572016-08-29 17:37:08 -070066 assertEquals("incorrect id", APPID, intent.appId());
67 assertEquals("incorrect match", MATCH, intent.selector());
Yi Tseng2a81c9d2016-09-14 10:14:24 -070068 assertEquals("incorrect filtered ingress", FP2, intent.filteredIngressPoint());
69 assertEquals("incorrect filtered egress", FPS1, intent.filteredEgressPoints());
Pier Ventre27d42572016-08-29 17:37:08 -070070
Yi Tseng2a81c9d2016-09-14 10:14:24 -070071 intent = createAnotherFiltered();
Pier Ventre27d42572016-08-29 17:37:08 -070072 assertEquals("incorrect id", APPID, intent.appId());
73 assertEquals("incorrect match", MATCH, intent.selector());
Yi Tseng2a81c9d2016-09-14 10:14:24 -070074 assertEquals("incorrect filtered ingress", FP1, intent.filteredIngressPoint());
75 assertEquals("incorrect filtered egress", FPS2, intent.filteredEgressPoints());
Pier Ventre27d42572016-08-29 17:37:08 -070076 }
77
Ray Milkey4f7e3632019-02-19 15:35:20 -080078 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'Connorf3d06162014-10-02 15:54:12 -070084 @Override
85 protected SinglePointToMultiPointIntent createOne() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070086 return SinglePointToMultiPointIntent.builder()
87 .appId(APPID)
88 .selector(MATCH)
89 .treatment(NOP)
Ray Milkey4f7e3632019-02-19 15:35:20 -080090 .filteredIngressPoint(new FilteredConnectPoint(P1))
91 .filteredEgressPoints(filterPoints(PS2))
Ray Milkeyebc5d222015-03-18 15:45:36 -070092 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -070093 }
94
95 @Override
96 protected SinglePointToMultiPointIntent createAnother() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070097 return SinglePointToMultiPointIntent.builder()
98 .appId(APPID)
99 .selector(MATCH)
100 .treatment(NOP)
Ray Milkey4f7e3632019-02-19 15:35:20 -0800101 .filteredIngressPoint(new FilteredConnectPoint(P2))
102 .filteredEgressPoints(filterPoints(PS1))
Ray Milkeyebc5d222015-03-18 15:45:36 -0700103 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -0700104 }
Pier Ventre27d42572016-08-29 17:37:08 -0700105
Luca Prete670ac5d2017-02-03 15:55:43 -0800106 protected SinglePointToMultiPointIntent createWithResourceGroup() {
107 return SinglePointToMultiPointIntent.builder()
108 .appId(APPID)
109 .selector(MATCH)
110 .treatment(NOP)
Ray Milkey4f7e3632019-02-19 15:35:20 -0800111 .filteredIngressPoint(new FilteredConnectPoint(P2))
112 .filteredEgressPoints(filterPoints(PS1))
Luca Prete670ac5d2017-02-03 15:55:43 -0800113 .resourceGroup(RESOURCE_GROUP)
114 .build();
115 }
116
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700117 protected SinglePointToMultiPointIntent createFilteredOne() {
Pier Ventre27d42572016-08-29 17:37:08 -0700118 return SinglePointToMultiPointIntent.builder()
119 .appId(APPID)
Pier Ventre27d42572016-08-29 17:37:08 -0700120 .treatment(NOP)
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700121 .filteredEgressPoints(FPS1)
122 .filteredIngressPoint(FP2)
Pier Ventre27d42572016-08-29 17:37:08 -0700123 .build();
124 }
125
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700126 protected SinglePointToMultiPointIntent createAnotherFiltered() {
Pier Ventre27d42572016-08-29 17:37:08 -0700127 return SinglePointToMultiPointIntent.builder()
128 .appId(APPID)
Pier Ventre27d42572016-08-29 17:37:08 -0700129 .treatment(NOP)
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700130 .filteredEgressPoints(FPS2)
131 .filteredIngressPoint(FP1)
Pier Ventre27d42572016-08-29 17:37:08 -0700132 .build();
133 }
134
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700135 protected SinglePointToMultiPointIntent createWrongIntent() {
Pier Ventre27d42572016-08-29 17:37:08 -0700136 return SinglePointToMultiPointIntent.builder()
137 .appId(APPID)
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700138 .treatment(NOP)
139 .selector(VLANMATCH1)
140 .filteredEgressPoints(FPS2)
141 .filteredIngressPoint(FP1)
Pier Ventre27d42572016-08-29 17:37:08 -0700142 .build();
143 }
144
Brian O'Connorf3d06162014-10-02 15:54:12 -0700145}