Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [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 | */ |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 16 | package org.onosproject.net.optical.intent.impl.compiler; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 17 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.TestApplicationId; |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.core.CoreService; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -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.Link; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 27 | import org.onosproject.net.OchSignalType; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 28 | import org.onosproject.net.flow.FlowRule; |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 29 | import org.onosproject.net.intent.AbstractIntentTest; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 30 | import org.onosproject.net.intent.FlowRuleIntent; |
| 31 | import org.onosproject.net.intent.Intent; |
| 32 | import org.onosproject.net.intent.IntentExtensionService; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 33 | import org.onosproject.net.intent.OpticalPathIntent; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 34 | |
| 35 | import java.util.Arrays; |
| 36 | import java.util.Collection; |
| 37 | import java.util.Collections; |
| 38 | import java.util.List; |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 39 | import java.util.stream.Collectors; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 40 | |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 41 | import static org.easymock.EasyMock.*; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 42 | import static org.hamcrest.MatcherAssert.assertThat; |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 43 | import static org.hamcrest.Matchers.*; |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 44 | import static org.junit.Assert.assertEquals; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 45 | import static org.onosproject.net.Link.Type.DIRECT; |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 46 | import static org.onosproject.net.NetTestTools.*; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 47 | |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 48 | public class OpticalPathIntentCompilerTest extends AbstractIntentTest { |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 49 | |
| 50 | private CoreService coreService; |
| 51 | private IntentExtensionService intentExtensionService; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 52 | private OpticalPathIntentCompiler sut; |
| 53 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 54 | private final ApplicationId appId = new TestApplicationId("test"); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 55 | private final ConnectPoint d1p1 = connectPoint("s1", 0); |
| 56 | private final ConnectPoint d2p0 = connectPoint("s2", 0); |
| 57 | private final ConnectPoint d2p1 = connectPoint("s2", 1); |
| 58 | private final ConnectPoint d3p1 = connectPoint("s3", 1); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 59 | |
| 60 | private final List<Link> links = Arrays.asList( |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 61 | DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(), |
| 62 | DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build() |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 63 | ); |
| 64 | private final int hops = links.size() + 1; |
| 65 | private OpticalPathIntent intent; |
| 66 | |
| 67 | @Before |
| 68 | public void setUp() { |
| 69 | sut = new OpticalPathIntentCompiler(); |
| 70 | coreService = createMock(CoreService.class); |
| 71 | expect(coreService.registerApplication("org.onosproject.net.intent")) |
| 72 | .andReturn(appId); |
| 73 | sut.coreService = coreService; |
| 74 | |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 75 | super.setUp(); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 76 | |
| 77 | intent = OpticalPathIntent.builder() |
| 78 | .appId(appId) |
| 79 | .src(d1p1) |
| 80 | .dst(d3p1) |
| 81 | .path(new DefaultPath(PID, links, hops)) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 82 | .lambda(createLambda()) |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 83 | .signalType(OchSignalType.FIXED_GRID) |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 84 | .build(); |
| 85 | intentExtensionService = createMock(IntentExtensionService.class); |
| 86 | intentExtensionService.registerCompiler(OpticalPathIntent.class, sut); |
| 87 | intentExtensionService.unregisterCompiler(OpticalPathIntent.class); |
| 88 | sut.intentManager = intentExtensionService; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 89 | |
| 90 | replay(coreService, intentExtensionService); |
| 91 | } |
| 92 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 93 | @Test |
| 94 | public void testCompiler() { |
| 95 | sut.activate(); |
| 96 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 97 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 98 | assertThat(compiled, hasSize(1)); |
| 99 | |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 100 | assertThat("key is inherited", |
| 101 | compiled.stream().map(Intent::key).collect(Collectors.toList()), |
| 102 | everyItem(is(intent.key()))); |
| 103 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 104 | Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); |
| 105 | rules.stream() |
| 106 | .filter(x -> x.deviceId().equals(d1p1.deviceId())) |
| 107 | .findFirst() |
| 108 | .get(); |
| 109 | |
| 110 | rules.stream() |
| 111 | .filter(x -> x.deviceId().equals(d2p1.deviceId())) |
| 112 | .findFirst() |
| 113 | .get(); |
| 114 | |
| 115 | rules.stream() |
| 116 | .filter(x -> x.deviceId().equals(d3p1.deviceId())) |
| 117 | .findFirst() |
| 118 | .get(); |
| 119 | |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 120 | rules.forEach(rule -> assertEquals("FlowRule priority is incorrect", |
| 121 | intent.priority(), rule.priority())); |
| 122 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 123 | sut.deactivate(); |
| 124 | } |
| 125 | |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 126 | //TODO test bidirectional optical paths and verify rules |
| 127 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 128 | } |