Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 18 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.ConnectPoint; |
| 20 | import org.onosproject.net.DefaultLink; |
| 21 | import org.onosproject.net.DefaultPath; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.NetTestTools; |
| 24 | import org.onosproject.net.Path; |
| 25 | import org.onosproject.net.PortNumber; |
| 26 | import org.onosproject.net.provider.ProviderId; |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 27 | |
| 28 | import java.util.Arrays; |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 29 | |
| 30 | import static org.junit.Assert.assertEquals; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import static org.onosproject.net.DeviceId.deviceId; |
| 32 | import static org.onosproject.net.Link.Type.DIRECT; |
| 33 | import static org.onosproject.net.PortNumber.portNumber; |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 34 | |
| 35 | public class PathIntentTest extends ConnectivityIntentTest { |
| 36 | // 111:11 --> 222:22 |
| 37 | private static final Path PATH1 = NetTestTools.createPath("111", "222"); |
| 38 | |
| 39 | // 111:11 --> 333:33 |
| 40 | private static final Path PATH2 = NetTestTools.createPath("222", "333"); |
| 41 | |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 42 | private final ProviderId provider1 = new ProviderId("of", "1"); |
| 43 | private final DeviceId device1 = deviceId("1"); |
| 44 | private final DeviceId device2 = deviceId("2"); |
| 45 | private final PortNumber port1 = portNumber(1); |
| 46 | private final PortNumber port2 = portNumber(2); |
| 47 | private final PortNumber port3 = portNumber(3); |
| 48 | private final PortNumber port4 = portNumber(4); |
| 49 | private final ConnectPoint cp1 = new ConnectPoint(device1, port1); |
| 50 | private final ConnectPoint cp2 = new ConnectPoint(device1, port2); |
| 51 | private final ConnectPoint cp3 = new ConnectPoint(device2, port3); |
| 52 | private final ConnectPoint cp4 = new ConnectPoint(device2, port4); |
| 53 | private final DefaultLink link1 = new DefaultLink(provider1, cp1, cp2, DIRECT); |
| 54 | private final DefaultLink link2 = new DefaultLink(provider1, cp1, cp2, DIRECT); |
| 55 | private final double cost = 1; |
| 56 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 57 | @Test |
| 58 | public void basics() { |
| 59 | PathIntent intent = createOne(); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 60 | assertEquals("incorrect id", APPID, intent.appId()); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 61 | assertEquals("incorrect match", MATCH, intent.selector()); |
| 62 | assertEquals("incorrect action", NOP, intent.treatment()); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 63 | assertEquals("incorrect path", PATH1, intent.path()); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
| 67 | protected PathIntent createOne() { |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 68 | return new PathIntent(APPID, MATCH, NOP, PATH1); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | protected PathIntent createAnother() { |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 73 | return new PathIntent(APPID, MATCH, NOP, PATH2); |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 74 | } |
Sho SHIMIZU | 3908fde | 2014-11-19 16:30:22 -0800 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * Tests the constructor raises IllegalArgumentException when the same device is specified in |
| 78 | * source and destination of a link. |
| 79 | */ |
| 80 | @Test(expected = IllegalArgumentException.class) |
| 81 | public void testRaiseExceptionWhenSameDevices() { |
| 82 | new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1), cost)); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Tests the constructor raises IllegalArgumentException when the different elements are specified |
| 87 | * in source element of the first link and destination element of the second link. |
| 88 | */ |
| 89 | @Test(expected = IllegalArgumentException.class) |
| 90 | public void testRaiseExceptionWhenDifferentDevice() { |
| 91 | new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1, link2), cost)); |
| 92 | } |
| 93 | |
Brian O'Connor | f3d0616 | 2014-10-02 15:54:12 -0700 | [diff] [blame] | 94 | } |