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