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 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 18 | import java.util.Arrays; |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 19 | import java.util.Collections; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 20 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 21 | import org.junit.Test; |
Ray Milkey | a7cf8c8 | 2018-02-08 15:07:06 -0800 | [diff] [blame] | 22 | import org.onlab.graph.ScalarWeight; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.DefaultLink; |
| 25 | import org.onosproject.net.DefaultPath; |
| 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.NetTestTools; |
| 28 | import org.onosproject.net.Path; |
| 29 | import org.onosproject.net.PortNumber; |
| 30 | import org.onosproject.net.provider.ProviderId; |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 31 | |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 32 | import static org.junit.Assert.assertEquals; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import static org.onosproject.net.DeviceId.deviceId; |
| 34 | import static org.onosproject.net.Link.Type.DIRECT; |
| 35 | import static org.onosproject.net.PortNumber.portNumber; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 36 | |
| 37 | public class PathIntentTest extends ConnectivityIntentTest { |
| 38 | // 111:11 --> 222:22 |
| 39 | private static final Path PATH1 = NetTestTools.createPath("111", "222"); |
| 40 | |
| 41 | // 111:11 --> 333:33 |
| 42 | private static final Path PATH2 = NetTestTools.createPath("222", "333"); |
| 43 | |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 44 | private final ProviderId provider1 = new ProviderId("of", "1"); |
| 45 | private final DeviceId device1 = deviceId("1"); |
| 46 | private final DeviceId device2 = deviceId("2"); |
| 47 | private final PortNumber port1 = portNumber(1); |
| 48 | private final PortNumber port2 = portNumber(2); |
| 49 | private final PortNumber port3 = portNumber(3); |
| 50 | private final PortNumber port4 = portNumber(4); |
| 51 | private final ConnectPoint cp1 = new ConnectPoint(device1, port1); |
| 52 | private final ConnectPoint cp2 = new ConnectPoint(device1, port2); |
| 53 | private final ConnectPoint cp3 = new ConnectPoint(device2, port3); |
| 54 | private final ConnectPoint cp4 = new ConnectPoint(device2, port4); |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 55 | private final DefaultLink link1 = DefaultLink.builder() |
| 56 | .providerId(provider1) |
| 57 | .src(cp1) |
| 58 | .dst(cp2) |
| 59 | .type(DIRECT) |
| 60 | .build(); |
| 61 | private final DefaultLink link2 = DefaultLink.builder() |
| 62 | .providerId(provider1) |
| 63 | .src(cp1) |
| 64 | .dst(cp2) |
| 65 | .type(DIRECT) |
| 66 | .build(); |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 67 | private final double cost = 1; |
| 68 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 69 | @Test |
| 70 | public void basics() { |
| 71 | PathIntent intent = createOne(); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 72 | assertEquals("incorrect id", APPID, intent.appId()); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 73 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 74 | assertEquals("incorrect action", NOP, intent.treatment()); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 75 | assertEquals("incorrect path", PATH1, intent.path()); |
ilhem fajjari | b0a0684 | 2015-11-02 18:59:02 +0100 | [diff] [blame] | 76 | assertEquals("incorrect key", KEY, intent.key()); |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 77 | |
| 78 | intent = createAnother(); |
| 79 | assertEquals("incorrect id", APPID, intent.appId()); |
| 80 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 81 | assertEquals("incorrect action", NOP, intent.treatment()); |
| 82 | assertEquals("incorrect path", PATH2, intent.path()); |
| 83 | assertEquals("incorrect key", KEY, intent.key()); |
| 84 | |
| 85 | intent = createWithResourceGroup(); |
| 86 | assertEquals("incorrect id", APPID, intent.appId()); |
| 87 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 88 | assertEquals("incorrect action", NOP, intent.treatment()); |
| 89 | assertEquals("incorrect path", PATH2, intent.path()); |
| 90 | assertEquals("incorrect key", KEY, intent.key()); |
| 91 | assertEquals("incorrect resource group", RESOURCE_GROUP, intent.resourceGroup()); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | @Override |
| 95 | protected PathIntent createOne() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 96 | return PathIntent.builder() |
| 97 | .appId(APPID) |
ilhem fajjari | b0a0684 | 2015-11-02 18:59:02 +0100 | [diff] [blame] | 98 | .key(KEY) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 99 | .selector(MATCH) |
| 100 | .treatment(NOP) |
| 101 | .path(PATH1) |
| 102 | .build(); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
| 106 | protected PathIntent createAnother() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 107 | return PathIntent.builder() |
| 108 | .appId(APPID) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 109 | .key(KEY) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 110 | .selector(MATCH) |
| 111 | .treatment(NOP) |
| 112 | .path(PATH2) |
| 113 | .build(); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 114 | } |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 115 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 116 | protected PathIntent createWithResourceGroup() { |
| 117 | return PathIntent.builder() |
| 118 | .appId(APPID) |
| 119 | .key(KEY) |
| 120 | .selector(MATCH) |
| 121 | .treatment(NOP) |
| 122 | .path(PATH2) |
| 123 | .resourceGroup(RESOURCE_GROUP) |
| 124 | .build(); |
| 125 | } |
| 126 | |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 127 | /** |
| 128 | * Tests the constructor raises IllegalArgumentException when the same device is specified in |
| 129 | * source and destination of a link. |
| 130 | */ |
| 131 | @Test(expected = IllegalArgumentException.class) |
| 132 | public void testRaiseExceptionWhenSameDevices() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 133 | PathIntent.builder() |
| 134 | .appId(APPID) |
| 135 | .selector(MATCH) |
| 136 | .treatment(NOP) |
Ray Milkey | a7cf8c8 | 2018-02-08 15:07:06 -0800 | [diff] [blame] | 137 | .path(new DefaultPath(provider1, Collections.singletonList(link1), ScalarWeight.toWeight(cost))) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 138 | .build(); |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Tests the constructor raises IllegalArgumentException when the different elements are specified |
| 143 | * in source element of the first link and destination element of the second link. |
| 144 | */ |
| 145 | @Test(expected = IllegalArgumentException.class) |
| 146 | public void testRaiseExceptionWhenDifferentDevice() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 147 | PathIntent.builder() |
| 148 | .appId(APPID) |
| 149 | .selector(MATCH) |
| 150 | .treatment(NOP) |
Ray Milkey | a7cf8c8 | 2018-02-08 15:07:06 -0800 | [diff] [blame] | 151 | .path(new DefaultPath(provider1, Arrays.asList(link1, link2), ScalarWeight.toWeight(cost))) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 152 | .build(); |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 155 | } |