Phaneendra Manda
Committed by Gerrit Code Review

[ONOS-4612]Update SFC flows inline with the Official OVS NSH patch

Change-Id: If58517841096a939860d88aa78eca7cae46b9935
Showing 61 changed files with 2256 additions and 373 deletions
1 -/*
2 - * Copyright 2015-present 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 - */
16 -package org.onosproject.sfc.forwarder;
17 -
18 -import java.util.List;
19 -
20 -import org.onosproject.net.NshServicePathId;
21 -import org.onosproject.vtnrsc.PortChain;
22 -import org.onosproject.vtnrsc.PortPairId;
23 -
24 -/**
25 - * Abstraction of an entity which provides service function forwarder.
26 - */
27 -public interface ServiceFunctionForwarderService {
28 -
29 - /**
30 - * Install forwarding rule.
31 - *
32 - * @param portChain port-chain
33 - * @param nshSpi nsh spi
34 - */
35 - @Deprecated
36 - void installForwardingRule(PortChain portChain, NshServicePathId nshSpi);
37 -
38 - /**
39 - * Uninstall forwarding rule.
40 - *
41 - * @param portChain port-chain
42 - * @param nshSpi nsh spi
43 - */
44 - @Deprecated
45 - void unInstallForwardingRule(PortChain portChain, NshServicePathId nshSpi);
46 -
47 - /**
48 - * Install load balanced forwarding rules.
49 - *
50 - * @param path load balanced path of port pairs
51 - * @param nshSpi nsh service path index
52 - */
53 - void installLoadBalancedForwardingRule(List<PortPairId> path, NshServicePathId nshSpi);
54 -
55 - /**
56 - * Uninstall load balanced forwarding rules.
57 - *
58 - * @param path load balanced path of port pairs
59 - * @param nshSpi nsh service path index
60 - */
61 - void unInstallLoadBalancedForwardingRule(List<PortPairId> path, NshServicePathId nshSpi);
62 -}
1 -/*
2 - * Copyright 2015-present 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 - */
16 -
17 -/**
18 - * Service function forwarder for SFC.
19 - */
20 -package org.onosproject.sfc.forwarder;
...@@ -23,7 +23,7 @@ import org.onosproject.vtnrsc.PortChain; ...@@ -23,7 +23,7 @@ import org.onosproject.vtnrsc.PortChain;
23 /** 23 /**
24 * Abstraction of an entity which installs flow classification rules in ovs. 24 * Abstraction of an entity which installs flow classification rules in ovs.
25 */ 25 */
26 -public interface FlowClassifierInstallerService { 26 +public interface SfcFlowRuleInstallerService {
27 27
28 /** 28 /**
29 * Install flow classifier. 29 * Install flow classifier.
...@@ -44,24 +44,24 @@ public interface FlowClassifierInstallerService { ...@@ -44,24 +44,24 @@ public interface FlowClassifierInstallerService {
44 ConnectPoint unInstallFlowClassifier(PortChain portChain, NshServicePathId nshSpiId); 44 ConnectPoint unInstallFlowClassifier(PortChain portChain, NshServicePathId nshSpiId);
45 45
46 /** 46 /**
47 - * Install load balanced flow classifier. 47 + * Install load balanced flow rules.
48 * 48 *
49 * @param portChain port-chain 49 * @param portChain port-chain
50 * @param fiveTuple five tuple packet information 50 * @param fiveTuple five tuple packet information
51 * @param nshSpiId service path index identifier 51 * @param nshSpiId service path index identifier
52 * @return connectPoint the network identifier 52 * @return connectPoint the network identifier
53 */ 53 */
54 - ConnectPoint installLoadBalancedFlowClassifier(PortChain portChain, FiveTuple fiveTuple, 54 + ConnectPoint installLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple,
55 - NshServicePathId nshSpiId); 55 + NshServicePathId nshSpiId);
56 56
57 /** 57 /**
58 - * Uninstall load balanced flow classifier. 58 + * Uninstall load balanced flow rules.
59 * 59 *
60 * @param portChain port-chain 60 * @param portChain port-chain
61 * @param fiveTuple five tuple packet information 61 * @param fiveTuple five tuple packet information
62 * @param nshSpiId service path index identifier 62 * @param nshSpiId service path index identifier
63 * @return connectPoint the network identifier 63 * @return connectPoint the network identifier
64 */ 64 */
65 - ConnectPoint unInstallLoadBalancedFlowClassifier(PortChain portChain, FiveTuple fiveTuple, 65 + ConnectPoint unInstallLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple,
66 - NshServicePathId nshSpiId); 66 + NshServicePathId nshSpiId);
67 } 67 }
......
1 -/*
2 - * Copyright 2016-present 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 - */
16 -package org.onosproject.sfc.forwarder.impl;
17 -
18 -import static org.easymock.EasyMock.createMock;
19 -import static org.easymock.EasyMock.expect;
20 -import static org.easymock.EasyMock.replay;
21 -import static org.hamcrest.Matchers.instanceOf;
22 -import static org.hamcrest.Matchers.is;
23 -import static org.junit.Assert.assertThat;
24 -
25 -import java.util.List;
26 -import java.util.Map;
27 -import java.util.Set;
28 -
29 -import org.junit.Test;
30 -import org.onlab.packet.IpAddress;
31 -import org.onlab.packet.MacAddress;
32 -import org.onosproject.core.ApplicationId;
33 -import org.onosproject.core.DefaultApplicationId;
34 -import org.onosproject.net.DeviceId;
35 -import org.onosproject.net.NshServicePathId;
36 -import org.onosproject.net.PortNumber;
37 -import org.onosproject.net.device.DeviceService;
38 -import org.onosproject.net.device.DeviceServiceAdapter;
39 -import org.onosproject.net.driver.DriverHandler;
40 -import org.onosproject.net.driver.DriverService;
41 -import org.onosproject.net.flow.criteria.Criterion;
42 -import org.onosproject.net.flow.criteria.PortCriterion;
43 -import org.onosproject.net.flow.instructions.Instruction;
44 -import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
45 -import org.onosproject.net.flowobjective.FlowObjectiveService;
46 -import org.onosproject.net.flowobjective.ForwardingObjective;
47 -import org.onosproject.net.host.HostService;
48 -import org.onosproject.net.host.HostServiceAdapter;
49 -import org.onosproject.sfc.util.FlowClassifierAdapter;
50 -import org.onosproject.sfc.util.FlowObjectiveAdapter;
51 -import org.onosproject.sfc.util.MockDriverHandler;
52 -import org.onosproject.sfc.util.PortPairAdapter;
53 -import org.onosproject.sfc.util.PortPairGroupAdapter;
54 -import org.onosproject.sfc.util.VirtualPortAdapter;
55 -import org.onosproject.sfc.util.VtnRscAdapter;
56 -import org.onosproject.vtnrsc.AllowedAddressPair;
57 -import org.onosproject.vtnrsc.BindingHostId;
58 -import org.onosproject.vtnrsc.DefaultPortPair;
59 -import org.onosproject.vtnrsc.DefaultVirtualPort;
60 -import org.onosproject.vtnrsc.FixedIp;
61 -import org.onosproject.vtnrsc.PortPair;
62 -import org.onosproject.vtnrsc.PortPairId;
63 -import org.onosproject.vtnrsc.SecurityGroup;
64 -import org.onosproject.vtnrsc.SubnetId;
65 -import org.onosproject.vtnrsc.TenantId;
66 -import org.onosproject.vtnrsc.TenantNetworkId;
67 -import org.onosproject.vtnrsc.VirtualPort;
68 -import org.onosproject.vtnrsc.VirtualPortId;
69 -import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
70 -import org.onosproject.vtnrsc.portpair.PortPairService;
71 -import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
72 -import org.onosproject.vtnrsc.service.VtnRscService;
73 -import org.onosproject.vtnrsc.virtualport.VirtualPortService;
74 -
75 -import com.google.common.collect.Lists;
76 -import com.google.common.collect.Maps;
77 -import com.google.common.collect.Sets;
78 -
79 -public class ServiceFunctionForwarderImplTest {
80 -
81 - FlowObjectiveService flowObjectiveService = new FlowObjectiveAdapter();
82 - DeviceService deviceService = new DeviceServiceAdapter();
83 - HostService hostService = new HostServiceAdapter();
84 - VirtualPortService virtualPortService = new VirtualPortAdapter();
85 - VtnRscService vtnRscService = new VtnRscAdapter();
86 - PortPairService portPairService = new PortPairAdapter();
87 - PortPairGroupService portPairGroupService = new PortPairGroupAdapter();
88 - FlowClassifierService flowClassifierService = new FlowClassifierAdapter();
89 -
90 - final DriverService driverService = createMock(DriverService.class);
91 -
92 - DeviceId deviceId = DeviceId.deviceId("of:000000000000001");
93 - final TenantId tenantId = TenantId.tenantId("1");
94 -
95 - final DriverHandler driverHandler = new MockDriverHandler();
96 -
97 - private VirtualPort createVirtualPort(VirtualPortId id) {
98 - Set<FixedIp> fixedIps;
99 - Map<String, String> propertyMap;
100 - Set<AllowedAddressPair> allowedAddressPairs;
101 - Set<SecurityGroup> securityGroups = Sets.newHashSet();
102 -
103 - String macAddressStr = "fa:12:3e:56:ee:a2";
104 - String ipAddress = "10.1.1.1";
105 - String tenantNetworkId = "1234567";
106 - String subnet = "1212";
107 - String hostIdStr = "fa:e2:3e:56:ee:a2";
108 - String deviceOwner = "james";
109 - propertyMap = Maps.newHashMap();
110 - propertyMap.putIfAbsent("deviceOwner", deviceOwner);
111 -
112 - TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId);
113 - MacAddress macAddress = MacAddress.valueOf(macAddressStr);
114 - BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr);
115 - FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet),
116 - IpAddress.valueOf(ipAddress));
117 - fixedIps = Sets.newHashSet();
118 - fixedIps.add(fixedIp);
119 -
120 - allowedAddressPairs = Sets.newHashSet();
121 - AllowedAddressPair allowedAddressPair = AllowedAddressPair
122 - .allowedAddressPair(IpAddress.valueOf(ipAddress),
123 - MacAddress.valueOf(macAddressStr));
124 - allowedAddressPairs.add(allowedAddressPair);
125 -
126 - VirtualPort d1 = new DefaultVirtualPort(id, networkId, true,
127 - propertyMap,
128 - VirtualPort.State.ACTIVE,
129 - macAddress, tenantId, deviceId,
130 - fixedIps, bindingHostId,
131 - allowedAddressPairs,
132 - securityGroups);
133 - return d1;
134 - }
135 -
136 - @Test
137 - public void testInstallFlowClassifier() {
138 -
139 - PortPairId portPairId1 = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
140 - PortPairId portPairId2 = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
141 -
142 - final String ppName1 = "PortPair1";
143 - final String ppDescription1 = "PortPair1";
144 - final String ingress1 = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
145 - final String egress1 = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
146 - DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
147 - PortPair portPair1 = portPairBuilder.setId(portPairId1).setName(ppName1).setTenantId(tenantId)
148 - .setDescription(ppDescription1).setIngress(ingress1).setEgress(egress1).build();
149 -
150 - final String ppName2 = "PortPair2";
151 - final String ppDescription2 = "PortPair2";
152 - final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1";
153 - final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345";
154 - PortPair portPair2 = portPairBuilder.setId(portPairId2).setName(ppName2).setTenantId(tenantId)
155 - .setDescription(ppDescription2).setIngress(ingress2).setEgress(egress2).build();
156 -
157 - ApplicationId appId = new DefaultApplicationId(1, "test");
158 - ServiceFunctionForwarderImpl serviceFunctionForwarder = new ServiceFunctionForwarderImpl();
159 - serviceFunctionForwarder.virtualPortService = virtualPortService;
160 - serviceFunctionForwarder.vtnRscService = vtnRscService;
161 - serviceFunctionForwarder.portPairService = portPairService;
162 - serviceFunctionForwarder.portPairGroupService = portPairGroupService;
163 - serviceFunctionForwarder.flowClassifierService = flowClassifierService;
164 - serviceFunctionForwarder.driverService = driverService;
165 - serviceFunctionForwarder.hostService = hostService;
166 - serviceFunctionForwarder.flowObjectiveService = flowObjectiveService;
167 - serviceFunctionForwarder.appId = appId;
168 -
169 - NshServicePathId nshSpiId = NshServicePathId.of(10);
170 -
171 - portPairService.createPortPair(portPair1);
172 - portPairService.createPortPair(portPair2);
173 -
174 - List<PortPairId> path = Lists.newArrayList();
175 - path.add(portPairId1);
176 - path.add(portPairId2);
177 -
178 - List<VirtualPort> virtualPortList = Lists.newArrayList();
179 - virtualPortList.add(createVirtualPort(VirtualPortId.portId(egress1)));
180 - virtualPortList.add(createVirtualPort(VirtualPortId.portId(ingress2)));
181 - virtualPortService.createPorts(virtualPortList);
182 -
183 - expect(driverService.createHandler(deviceId)).andReturn(driverHandler).anyTimes();
184 - replay(driverService);
185 -
186 - serviceFunctionForwarder.installLoadBalancedForwardingRule(path, nshSpiId);
187 -
188 - ForwardingObjective forObj = ((FlowObjectiveAdapter) flowObjectiveService).forwardingObjective();
189 -
190 - // Check for Selector
191 - assertThat(forObj.selector().getCriterion(Criterion.Type.IN_PORT), instanceOf(PortCriterion.class));
192 -
193 - // Check for treatment
194 - List<Instruction> instructions = forObj.treatment().allInstructions();
195 - for (Instruction instruction : instructions) {
196 - if (instruction.type() == Instruction.Type.OUTPUT) {
197 - assertThat(((OutputInstruction) instruction).port(), is(PortNumber.P0));
198 - }
199 - }
200 - }
201 -}
...\ No newline at end of file ...\ No newline at end of file
...@@ -23,6 +23,12 @@ import org.onosproject.net.flow.instructions.ExtensionPropertyException; ...@@ -23,6 +23,12 @@ import org.onosproject.net.flow.instructions.ExtensionPropertyException;
23 23
24 public class MockExtensionSelector implements ExtensionSelector { 24 public class MockExtensionSelector implements ExtensionSelector {
25 25
26 + private ExtensionSelectorType type;
27 +
28 + public MockExtensionSelector(ExtensionSelectorType type) {
29 + this.type = type;
30 + }
31 +
26 @Override 32 @Override
27 public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException { 33 public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException {
28 } 34 }
...@@ -48,6 +54,6 @@ public class MockExtensionSelector implements ExtensionSelector { ...@@ -48,6 +54,6 @@ public class MockExtensionSelector implements ExtensionSelector {
48 54
49 @Override 55 @Override
50 public ExtensionSelectorType type() { 56 public ExtensionSelectorType type() {
51 - return null; 57 + return type;
52 } 58 }
53 } 59 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -43,6 +43,6 @@ public class MockExtensionSelectorResolver implements ExtensionSelectorResolver ...@@ -43,6 +43,6 @@ public class MockExtensionSelectorResolver implements ExtensionSelectorResolver
43 43
44 @Override 44 @Override
45 public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) { 45 public ExtensionSelector getExtensionSelector(ExtensionSelectorType type) {
46 - return new MockExtensionSelector(); 46 + return new MockExtensionSelector(type);
47 } 47 }
48 } 48 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -23,6 +23,12 @@ import org.onosproject.net.flow.instructions.ExtensionTreatmentType; ...@@ -23,6 +23,12 @@ import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
23 23
24 public class MockExtensionTreatment implements ExtensionTreatment { 24 public class MockExtensionTreatment implements ExtensionTreatment {
25 25
26 + private ExtensionTreatmentType type;
27 +
28 + public MockExtensionTreatment(ExtensionTreatmentType type) {
29 + this.type = type;
30 + }
31 +
26 @Override 32 @Override
27 public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException { 33 public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException {
28 } 34 }
...@@ -48,7 +54,7 @@ public class MockExtensionTreatment implements ExtensionTreatment { ...@@ -48,7 +54,7 @@ public class MockExtensionTreatment implements ExtensionTreatment {
48 54
49 @Override 55 @Override
50 public ExtensionTreatmentType type() { 56 public ExtensionTreatmentType type() {
51 - return null; 57 + return type;
52 } 58 }
53 59
54 } 60 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -43,7 +43,7 @@ public class MockExtensionTreatmentResolver implements ExtensionTreatmentResolve ...@@ -43,7 +43,7 @@ public class MockExtensionTreatmentResolver implements ExtensionTreatmentResolve
43 43
44 @Override 44 @Override
45 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) { 45 public ExtensionTreatment getExtensionInstruction(ExtensionTreatmentType type) {
46 - return new MockExtensionTreatment(); 46 + return new MockExtensionTreatment(type);
47 } 47 }
48 48
49 } 49 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.sfc.util;
17 +
18 +import java.util.concurrent.ConcurrentHashMap;
19 +import java.util.concurrent.ConcurrentMap;
20 +
21 +import org.onosproject.vtnrsc.TenantNetwork;
22 +import org.onosproject.vtnrsc.TenantNetworkId;
23 +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
24 +
25 +import com.google.common.collect.ImmutableList;
26 +
27 +/**
28 + * Provides implementation of the VtnRsc service.
29 + */
30 +public class TenantNetworkAdapter implements TenantNetworkService {
31 +
32 + private final ConcurrentMap<TenantNetworkId, TenantNetwork> tenantNetworkStore = new ConcurrentHashMap<>();
33 +
34 + @Override
35 + public boolean exists(TenantNetworkId networkId) {
36 + return tenantNetworkStore.containsKey(networkId);
37 + }
38 +
39 + @Override
40 + public int getNetworkCount() {
41 + return tenantNetworkStore.size();
42 + }
43 +
44 + @Override
45 + public Iterable<TenantNetwork> getNetworks() {
46 + return ImmutableList.copyOf(tenantNetworkStore.values());
47 + }
48 +
49 + @Override
50 + public TenantNetwork getNetwork(TenantNetworkId networkId) {
51 + return tenantNetworkStore.get(networkId);
52 + }
53 +
54 + @Override
55 + public boolean createNetworks(Iterable<TenantNetwork> networks) {
56 + for (TenantNetwork network : networks) {
57 + tenantNetworkStore.put(network.id(), network);
58 + if (!tenantNetworkStore.containsKey(network.id())) {
59 + return false;
60 + }
61 + }
62 + return true;
63 + }
64 +
65 + @Override
66 + public boolean updateNetworks(Iterable<TenantNetwork> networks) {
67 + return false;
68 + }
69 +
70 + @Override
71 + public boolean removeNetworks(Iterable<TenantNetworkId> networksIds) {
72 + return false;
73 + }
74 +
75 +}
...@@ -45,6 +45,20 @@ public final class VtnConfig { ...@@ -45,6 +45,20 @@ public final class VtnConfig {
45 { 45 {
46 put("key", "flow"); 46 put("key", "flow");
47 put("remote_ip", "flow"); 47 put("remote_ip", "flow");
48 + put("dst_port", "4790");
49 + put("in_nsi", "flow");
50 + put("in_nsp", "flow");
51 + put("out_nsi", "flow");
52 + put("out_nsp", "flow");
53 + put("in_nshc1", "flow");
54 + put("out_nshc1", "flow");
55 + put("in_nshc2", "flow");
56 + put("out_nshc2", "flow");
57 + put("in_nshc3", "flow");
58 + put("out_nshc3", "flow");
59 + put("in_nshc4", "flow");
60 + put("out_nshc4", "flow");
61 + put("exts", "gpe");
48 } 62 }
49 }; 63 };
50 /** 64 /**
......
...@@ -48,7 +48,7 @@ public final class DefaultFlowClassifier implements FlowClassifier { ...@@ -48,7 +48,7 @@ public final class DefaultFlowClassifier implements FlowClassifier {
48 private static final String TENANT_ID_NOT_NULL = "Tenant id can not be null."; 48 private static final String TENANT_ID_NOT_NULL = "Tenant id can not be null.";
49 private static final String NAME_NOT_NULL = "Name can not be null."; 49 private static final String NAME_NOT_NULL = "Name can not be null.";
50 private static final String ETHER_TYPE_NOT_NULL = "Ether Type can not be null."; 50 private static final String ETHER_TYPE_NOT_NULL = "Ether Type can not be null.";
51 - private static final int DEFAULT_CLASSIFIER_PRIORITY = 0xFFFF; 51 + private static final int DEFAULT_CLASSIFIER_PRIORITY = 0xCB20;
52 52
53 /** 53 /**
54 * Constructor to create default flow classifier. 54 * Constructor to create default flow classifier.
......
...@@ -22,7 +22,6 @@ import java.util.Iterator; ...@@ -22,7 +22,6 @@ import java.util.Iterator;
22 import java.util.List; 22 import java.util.List;
23 import java.util.Map; 23 import java.util.Map;
24 import java.util.Objects; 24 import java.util.Objects;
25 -import java.util.Optional;
26 import java.util.Set; 25 import java.util.Set;
27 import java.util.concurrent.ConcurrentHashMap; 26 import java.util.concurrent.ConcurrentHashMap;
28 27
...@@ -42,11 +41,13 @@ public final class DefaultPortChain implements PortChain { ...@@ -42,11 +41,13 @@ public final class DefaultPortChain implements PortChain {
42 private final String description; 41 private final String description;
43 private final List<PortPairGroupId> portPairGroupList; 42 private final List<PortPairGroupId> portPairGroupList;
44 private final List<FlowClassifierId> flowClassifierList; 43 private final List<FlowClassifierId> flowClassifierList;
44 + private final PortChain oldPortChain;
45 45
46 private final Map<FiveTuple, LoadBalanceId> sfcLoadBalanceIdMap = new ConcurrentHashMap<>(); 46 private final Map<FiveTuple, LoadBalanceId> sfcLoadBalanceIdMap = new ConcurrentHashMap<>();
47 private final Map<LoadBalanceId, List<PortPairId>> sfcLoadBalancePathMap = new ConcurrentHashMap<>(); 47 private final Map<LoadBalanceId, List<PortPairId>> sfcLoadBalancePathMap = new ConcurrentHashMap<>();
48 private final Map<LoadBalanceId, List<DeviceId>> sfcClassifiersMap = new ConcurrentHashMap<>(); 48 private final Map<LoadBalanceId, List<DeviceId>> sfcClassifiersMap = new ConcurrentHashMap<>();
49 private final Map<LoadBalanceId, List<DeviceId>> sfcForwardersMap = new ConcurrentHashMap<>(); 49 private final Map<LoadBalanceId, List<DeviceId>> sfcForwardersMap = new ConcurrentHashMap<>();
50 +
50 /** 51 /**
51 * Default constructor to create port chain. 52 * Default constructor to create port chain.
52 * 53 *
...@@ -58,9 +59,10 @@ public final class DefaultPortChain implements PortChain { ...@@ -58,9 +59,10 @@ public final class DefaultPortChain implements PortChain {
58 * @param flowClassifierList flow classifier list 59 * @param flowClassifierList flow classifier list
59 */ 60 */
60 private DefaultPortChain(PortChainId portChainId, TenantId tenantId, 61 private DefaultPortChain(PortChainId portChainId, TenantId tenantId,
61 - String name, String description, 62 + String name, String description,
62 - List<PortPairGroupId> portPairGroupList, 63 + List<PortPairGroupId> portPairGroupList,
63 - List<FlowClassifierId> flowClassifierList) { 64 + List<FlowClassifierId> flowClassifierList,
65 + PortChain portChain) {
64 66
65 this.portChainId = portChainId; 67 this.portChainId = portChainId;
66 this.tenantId = tenantId; 68 this.tenantId = tenantId;
...@@ -68,6 +70,20 @@ public final class DefaultPortChain implements PortChain { ...@@ -68,6 +70,20 @@ public final class DefaultPortChain implements PortChain {
68 this.description = description; 70 this.description = description;
69 this.portPairGroupList = portPairGroupList; 71 this.portPairGroupList = portPairGroupList;
70 this.flowClassifierList = flowClassifierList; 72 this.flowClassifierList = flowClassifierList;
73 + this.oldPortChain = portChain;
74 + }
75 +
76 + /**
77 + * To create port chain for update with old port chain.
78 + *
79 + * @param newPortChain updated port chain
80 + * @param oldPortChain old port chain
81 + * @return port chain
82 + */
83 + public static PortChain create(PortChain newPortChain, PortChain oldPortChain) {
84 + return new DefaultPortChain(newPortChain.portChainId(), newPortChain.tenantId(),
85 + newPortChain.name(), newPortChain.description(),
86 + newPortChain.portPairGroups(), newPortChain.flowClassifiers(), oldPortChain);
71 } 87 }
72 88
73 /** 89 /**
...@@ -109,7 +125,7 @@ public final class DefaultPortChain implements PortChain { ...@@ -109,7 +125,7 @@ public final class DefaultPortChain implements PortChain {
109 125
110 @Override 126 @Override
111 public List<PortPairGroupId> portPairGroups() { 127 public List<PortPairGroupId> portPairGroups() {
112 - return ImmutableList.copyOf(portPairGroupList); 128 + return ImmutableList.copyOf(portPairGroupList);
113 } 129 }
114 130
115 @Override 131 @Override
...@@ -118,6 +134,11 @@ public final class DefaultPortChain implements PortChain { ...@@ -118,6 +134,11 @@ public final class DefaultPortChain implements PortChain {
118 } 134 }
119 135
120 @Override 136 @Override
137 + public PortChain oldPortChain() {
138 + return oldPortChain;
139 + }
140 +
141 + @Override
121 public void addLoadBalancePath(FiveTuple fiveTuple, LoadBalanceId id, 142 public void addLoadBalancePath(FiveTuple fiveTuple, LoadBalanceId id,
122 List<PortPairId> path) { 143 List<PortPairId> path) {
123 this.sfcLoadBalanceIdMap.put(fiveTuple, id); 144 this.sfcLoadBalanceIdMap.put(fiveTuple, id);
...@@ -136,14 +157,14 @@ public final class DefaultPortChain implements PortChain { ...@@ -136,14 +157,14 @@ public final class DefaultPortChain implements PortChain {
136 157
137 @Override 158 @Override
138 public void removeSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) { 159 public void removeSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) {
139 - List<DeviceId> list = getSfcClassifiers(id); 160 + List<DeviceId> list = sfcClassifiersMap.get(id);
140 list.removeAll(classifierList); 161 list.removeAll(classifierList);
141 this.sfcForwardersMap.put(id, list); 162 this.sfcForwardersMap.put(id, list);
142 } 163 }
143 164
144 @Override 165 @Override
145 public void removeSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) { 166 public void removeSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) {
146 - List<DeviceId> list = getSfcForwarders(id); 167 + List<DeviceId> list = sfcForwardersMap.get(id);
147 list.removeAll(forwarderList); 168 list.removeAll(forwarderList);
148 this.sfcForwardersMap.put(id, list); 169 this.sfcForwardersMap.put(id, list);
149 } 170 }
...@@ -192,7 +213,7 @@ public final class DefaultPortChain implements PortChain { ...@@ -192,7 +213,7 @@ public final class DefaultPortChain implements PortChain {
192 } 213 }
193 214
194 @Override 215 @Override
195 - public Optional<LoadBalanceId> matchPath(List<PortPairId> path) { 216 + public LoadBalanceId matchPath(List<PortPairId> path) {
196 217
197 LoadBalanceId id = null; 218 LoadBalanceId id = null;
198 for (Map.Entry<LoadBalanceId, List<PortPairId>> entry : sfcLoadBalancePathMap.entrySet()) { 219 for (Map.Entry<LoadBalanceId, List<PortPairId>> entry : sfcLoadBalancePathMap.entrySet()) {
...@@ -202,7 +223,7 @@ public final class DefaultPortChain implements PortChain { ...@@ -202,7 +223,7 @@ public final class DefaultPortChain implements PortChain {
202 break; 223 break;
203 } 224 }
204 } 225 }
205 - return Optional.of(id); 226 + return id;
206 } 227 }
207 228
208 @Override 229 @Override
...@@ -267,6 +288,7 @@ public final class DefaultPortChain implements PortChain { ...@@ -267,6 +288,7 @@ public final class DefaultPortChain implements PortChain {
267 private String description; 288 private String description;
268 private List<PortPairGroupId> portPairGroupList; 289 private List<PortPairGroupId> portPairGroupList;
269 private List<FlowClassifierId> flowClassifierList; 290 private List<FlowClassifierId> flowClassifierList;
291 + private PortChain portChain;
270 292
271 @Override 293 @Override
272 public Builder setId(PortChainId portChainId) { 294 public Builder setId(PortChainId portChainId) {
...@@ -312,7 +334,7 @@ public final class DefaultPortChain implements PortChain { ...@@ -312,7 +334,7 @@ public final class DefaultPortChain implements PortChain {
312 checkNotNull(portPairGroupList, "Port pair groups cannot be null"); 334 checkNotNull(portPairGroupList, "Port pair groups cannot be null");
313 335
314 return new DefaultPortChain(portChainId, tenantId, name, description, 336 return new DefaultPortChain(portChainId, tenantId, name, description,
315 - portPairGroupList, flowClassifierList); 337 + portPairGroupList, flowClassifierList, portChain);
316 } 338 }
317 } 339 }
318 } 340 }
......
...@@ -95,6 +95,13 @@ public final class DefaultPortPairGroup implements PortPairGroup { ...@@ -95,6 +95,13 @@ public final class DefaultPortPairGroup implements PortPairGroup {
95 } 95 }
96 96
97 @Override 97 @Override
98 + public void resetLoad() {
99 + for (PortPairId portPairId : portPairList) {
100 + portPairLoadMap.put(portPairId, new Integer(0));
101 + }
102 + }
103 +
104 + @Override
98 public int getLoad(PortPairId portPairId) { 105 public int getLoad(PortPairId portPairId) {
99 return portPairLoadMap.get(portPairId); 106 return portPairLoadMap.get(portPairId);
100 } 107 }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 package org.onosproject.vtnrsc; 16 package org.onosproject.vtnrsc;
17 17
18 import java.util.List; 18 import java.util.List;
19 -import java.util.Optional;
20 import java.util.Set; 19 import java.util.Set;
21 20
22 import org.onosproject.net.DeviceId; 21 import org.onosproject.net.DeviceId;
...@@ -74,6 +73,13 @@ public interface PortChain { ...@@ -74,6 +73,13 @@ public interface PortChain {
74 List<FlowClassifierId> flowClassifiers(); 73 List<FlowClassifierId> flowClassifiers();
75 74
76 /** 75 /**
76 + * Returns the old port chain.
77 + *
78 + * @return old port chain
79 + */
80 + PortChain oldPortChain();
81 +
82 + /**
77 * Adds a new load balanced path. 83 * Adds a new load balanced path.
78 * 84 *
79 * @param fiveTuple five tuple from the packet 85 * @param fiveTuple five tuple from the packet
...@@ -182,7 +188,7 @@ public interface PortChain { ...@@ -182,7 +188,7 @@ public interface PortChain {
182 * @param path load balanced path 188 * @param path load balanced path
183 * @return load balance id if the path matches, null otherwise. 189 * @return load balance id if the path matches, null otherwise.
184 */ 190 */
185 - Optional<LoadBalanceId> matchPath(List<PortPairId> path); 191 + LoadBalanceId matchPath(List<PortPairId> path);
186 192
187 /** 193 /**
188 * Returns whether this port chain is an exact match to the port chain given 194 * Returns whether this port chain is an exact match to the port chain given
......
...@@ -67,6 +67,11 @@ public interface PortPairGroup { ...@@ -67,6 +67,11 @@ public interface PortPairGroup {
67 void addLoad(PortPairId portPairId); 67 void addLoad(PortPairId portPairId);
68 68
69 /** 69 /**
70 + * Reset the load for all the port pairs in the group.
71 + */
72 + void resetLoad();
73 +
74 + /**
70 * Get the load on the given port pair id. 75 * Get the load on the given port pair id.
71 * 76 *
72 * @param portPairId port pair id 77 * @param portPairId port pair id
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
15 */ 15 */
16 package org.onosproject.vtnrsc.flowclassifier.impl; 16 package org.onosproject.vtnrsc.flowclassifier.impl;
17 17
18 -import static org.slf4j.LoggerFactory.getLogger;
19 import static com.google.common.base.Preconditions.checkNotNull; 18 import static com.google.common.base.Preconditions.checkNotNull;
19 +import static org.slf4j.LoggerFactory.getLogger;
20 +
21 +import java.util.UUID;
20 22
21 import org.apache.felix.scr.annotations.Activate; 23 import org.apache.felix.scr.annotations.Activate;
22 import org.apache.felix.scr.annotations.Component; 24 import org.apache.felix.scr.annotations.Component;
...@@ -24,6 +26,7 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -24,6 +26,7 @@ import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Reference; 26 import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 27 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.apache.felix.scr.annotations.Service; 28 import org.apache.felix.scr.annotations.Service;
29 +import org.onlab.packet.IpPrefix;
27 import org.onlab.util.KryoNamespace; 30 import org.onlab.util.KryoNamespace;
28 import org.onosproject.event.AbstractListenerManager; 31 import org.onosproject.event.AbstractListenerManager;
29 import org.onosproject.store.serializers.KryoNamespaces; 32 import org.onosproject.store.serializers.KryoNamespaces;
...@@ -33,8 +36,11 @@ import org.onosproject.store.service.EventuallyConsistentMapListener; ...@@ -33,8 +36,11 @@ import org.onosproject.store.service.EventuallyConsistentMapListener;
33 import org.onosproject.store.service.MultiValuedTimestamp; 36 import org.onosproject.store.service.MultiValuedTimestamp;
34 import org.onosproject.store.service.StorageService; 37 import org.onosproject.store.service.StorageService;
35 import org.onosproject.store.service.WallClockTimestamp; 38 import org.onosproject.store.service.WallClockTimestamp;
36 -import org.onosproject.vtnrsc.FlowClassifierId; 39 +import org.onosproject.vtnrsc.DefaultFlowClassifier;
37 import org.onosproject.vtnrsc.FlowClassifier; 40 import org.onosproject.vtnrsc.FlowClassifier;
41 +import org.onosproject.vtnrsc.FlowClassifierId;
42 +import org.onosproject.vtnrsc.TenantId;
43 +import org.onosproject.vtnrsc.VirtualPortId;
38 import org.onosproject.vtnrsc.flowclassifier.FlowClassifierEvent; 44 import org.onosproject.vtnrsc.flowclassifier.FlowClassifierEvent;
39 import org.onosproject.vtnrsc.flowclassifier.FlowClassifierListener; 45 import org.onosproject.vtnrsc.flowclassifier.FlowClassifierListener;
40 import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; 46 import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
...@@ -71,7 +77,8 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie ...@@ -71,7 +77,8 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie
71 KryoNamespace.Builder serializer = KryoNamespace.newBuilder() 77 KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
72 .register(KryoNamespaces.API) 78 .register(KryoNamespaces.API)
73 .register(MultiValuedTimestamp.class) 79 .register(MultiValuedTimestamp.class)
74 - .register(FlowClassifier.class); 80 + .register(FlowClassifier.class, FlowClassifierId.class, UUID.class, IpPrefix.class,
81 + VirtualPortId.class, DefaultFlowClassifier.class, TenantId.class);
75 flowClassifierStore = storageService 82 flowClassifierStore = storageService
76 .<FlowClassifierId, FlowClassifier>eventuallyConsistentMapBuilder() 83 .<FlowClassifierId, FlowClassifier>eventuallyConsistentMapBuilder()
77 .withName("flowclassifierstore").withSerializer(serializer) 84 .withName("flowclassifierstore").withSerializer(serializer)
......
...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
19 import static org.slf4j.LoggerFactory.getLogger; 19 import static org.slf4j.LoggerFactory.getLogger;
20 20
21 import java.util.Collections; 21 import java.util.Collections;
22 +import java.util.UUID;
22 23
23 import org.apache.felix.scr.annotations.Activate; 24 import org.apache.felix.scr.annotations.Activate;
24 import org.apache.felix.scr.annotations.Component; 25 import org.apache.felix.scr.annotations.Component;
...@@ -28,6 +29,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -28,6 +29,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
28 import org.apache.felix.scr.annotations.Service; 29 import org.apache.felix.scr.annotations.Service;
29 import org.onlab.util.KryoNamespace; 30 import org.onlab.util.KryoNamespace;
30 import org.onosproject.event.AbstractListenerManager; 31 import org.onosproject.event.AbstractListenerManager;
32 +import org.onosproject.net.DeviceId;
31 import org.onosproject.store.serializers.KryoNamespaces; 33 import org.onosproject.store.serializers.KryoNamespaces;
32 import org.onosproject.store.service.EventuallyConsistentMap; 34 import org.onosproject.store.service.EventuallyConsistentMap;
33 import org.onosproject.store.service.EventuallyConsistentMapEvent; 35 import org.onosproject.store.service.EventuallyConsistentMapEvent;
...@@ -35,8 +37,15 @@ import org.onosproject.store.service.EventuallyConsistentMapListener; ...@@ -35,8 +37,15 @@ import org.onosproject.store.service.EventuallyConsistentMapListener;
35 import org.onosproject.store.service.MultiValuedTimestamp; 37 import org.onosproject.store.service.MultiValuedTimestamp;
36 import org.onosproject.store.service.StorageService; 38 import org.onosproject.store.service.StorageService;
37 import org.onosproject.store.service.WallClockTimestamp; 39 import org.onosproject.store.service.WallClockTimestamp;
40 +import org.onosproject.vtnrsc.DefaultPortChain;
41 +import org.onosproject.vtnrsc.FiveTuple;
42 +import org.onosproject.vtnrsc.FlowClassifierId;
43 +import org.onosproject.vtnrsc.LoadBalanceId;
38 import org.onosproject.vtnrsc.PortChain; 44 import org.onosproject.vtnrsc.PortChain;
39 import org.onosproject.vtnrsc.PortChainId; 45 import org.onosproject.vtnrsc.PortChainId;
46 +import org.onosproject.vtnrsc.PortPairGroupId;
47 +import org.onosproject.vtnrsc.PortPairId;
48 +import org.onosproject.vtnrsc.TenantId;
40 import org.onosproject.vtnrsc.portchain.PortChainEvent; 49 import org.onosproject.vtnrsc.portchain.PortChainEvent;
41 import org.onosproject.vtnrsc.portchain.PortChainListener; 50 import org.onosproject.vtnrsc.portchain.PortChainListener;
42 import org.onosproject.vtnrsc.portchain.PortChainService; 51 import org.onosproject.vtnrsc.portchain.PortChainService;
...@@ -71,7 +80,9 @@ public class PortChainManager extends AbstractListenerManager<PortChainEvent, Po ...@@ -71,7 +80,9 @@ public class PortChainManager extends AbstractListenerManager<PortChainEvent, Po
71 KryoNamespace.Builder serializer = KryoNamespace.newBuilder() 80 KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
72 .register(KryoNamespaces.API) 81 .register(KryoNamespaces.API)
73 .register(MultiValuedTimestamp.class) 82 .register(MultiValuedTimestamp.class)
74 - .register(PortChain.class); 83 + .register(PortChain.class, PortChainId.class, UUID.class, PortPairGroupId.class,
84 + FlowClassifierId.class, FiveTuple.class, LoadBalanceId.class, DeviceId.class,
85 + DefaultPortChain.class, PortPairId.class, TenantId.class);
75 86
76 portChainStore = storageService 87 portChainStore = storageService
77 .<PortChainId, PortChain>eventuallyConsistentMapBuilder() 88 .<PortChainId, PortChain>eventuallyConsistentMapBuilder()
...@@ -118,7 +129,7 @@ public class PortChainManager extends AbstractListenerManager<PortChainEvent, Po ...@@ -118,7 +129,7 @@ public class PortChainManager extends AbstractListenerManager<PortChainEvent, Po
118 129
119 portChainStore.put(portChain.portChainId(), portChain); 130 portChainStore.put(portChain.portChainId(), portChain);
120 if (!portChainStore.containsKey(portChain.portChainId())) { 131 if (!portChainStore.containsKey(portChain.portChainId())) {
121 - log.debug("The portChain is created failed which identifier was {}", portChain.portChainId() 132 + log.error("The portChain created is failed which identifier was {}", portChain.portChainId()
122 .toString()); 133 .toString());
123 return false; 134 return false;
124 } 135 }
...@@ -128,18 +139,20 @@ public class PortChainManager extends AbstractListenerManager<PortChainEvent, Po ...@@ -128,18 +139,20 @@ public class PortChainManager extends AbstractListenerManager<PortChainEvent, Po
128 @Override 139 @Override
129 public boolean updatePortChain(PortChain portChain) { 140 public boolean updatePortChain(PortChain portChain) {
130 checkNotNull(portChain, PORT_CHAIN_NULL); 141 checkNotNull(portChain, PORT_CHAIN_NULL);
131 - 142 + PortChain oldPortChain = null;
132 if (!portChainStore.containsKey(portChain.portChainId())) { 143 if (!portChainStore.containsKey(portChain.portChainId())) {
133 - log.debug("The portChain is not exist whose identifier was {} ", 144 + log.warn("The portChain is not exist whose identifier was {} ",
134 - portChain.portChainId().toString()); 145 + portChain.portChainId().toString());
135 return false; 146 return false;
147 + } else {
148 + oldPortChain = portChainStore.get(portChain.portChainId());
136 } 149 }
150 + PortChain newPortChain = DefaultPortChain.create(portChain, oldPortChain);
151 + portChainStore.put(newPortChain.portChainId(), newPortChain);
137 152
138 - portChainStore.put(portChain.portChainId(), portChain); 153 + if (!newPortChain.equals(portChainStore.get(newPortChain.portChainId()))) {
139 -
140 - if (!portChain.equals(portChainStore.get(portChain.portChainId()))) {
141 log.debug("The portChain is updated failed whose identifier was {} ", 154 log.debug("The portChain is updated failed whose identifier was {} ",
142 - portChain.portChainId().toString()); 155 + newPortChain.portChainId().toString());
143 return false; 156 return false;
144 } 157 }
145 return true; 158 return true;
......
...@@ -38,6 +38,7 @@ import org.onosproject.vtnrsc.portpair.PortPairService; ...@@ -38,6 +38,7 @@ import org.onosproject.vtnrsc.portpair.PortPairService;
38 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; 38 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
39 import org.slf4j.Logger; 39 import org.slf4j.Logger;
40 40
41 +import com.google.common.collect.ImmutableList;
41 import com.google.common.collect.Lists; 42 import com.google.common.collect.Lists;
42 43
43 /** 44 /**
...@@ -86,13 +87,13 @@ public class PortChainSfMapManager implements PortChainSfMapService { ...@@ -86,13 +87,13 @@ public class PortChainSfMapManager implements PortChainSfMapService {
86 List<PortPairGroupId> portPairGrpList = portChain.portPairGroups(); 87 List<PortPairGroupId> portPairGrpList = portChain.portPairGroups();
87 ListIterator<PortPairGroupId> listGrpIterator = portPairGrpList.listIterator(); 88 ListIterator<PortPairGroupId> listGrpIterator = portPairGrpList.listIterator();
88 89
89 - while (listGrpIterator.next() != null) { 90 + while (listGrpIterator.hasNext()) {
90 PortPairGroupId portPairGroupId = listGrpIterator.next(); 91 PortPairGroupId portPairGroupId = listGrpIterator.next();
91 PortPairGroup portPairGroup = portPairGroupService.getPortPairGroup(portPairGroupId); 92 PortPairGroup portPairGroup = portPairGroupService.getPortPairGroup(portPairGroupId);
92 ServiceFunctionGroup sfg = new ServiceFunctionGroup(portPairGroup.name(), portPairGroup.description(), 93 ServiceFunctionGroup sfg = new ServiceFunctionGroup(portPairGroup.name(), portPairGroup.description(),
93 portPairGroup.portPairLoadMap()); 94 portPairGroup.portPairLoadMap());
94 serviceFunctionGroupList.add(sfg); 95 serviceFunctionGroupList.add(sfg);
95 } 96 }
96 - return serviceFunctionGroupList; 97 + return ImmutableList.copyOf(serviceFunctionGroupList);
97 } 98 }
98 } 99 }
......
...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
19 import static org.slf4j.LoggerFactory.getLogger; 19 import static org.slf4j.LoggerFactory.getLogger;
20 20
21 import java.util.Collections; 21 import java.util.Collections;
22 +import java.util.UUID;
22 23
23 import org.apache.felix.scr.annotations.Activate; 24 import org.apache.felix.scr.annotations.Activate;
24 import org.apache.felix.scr.annotations.Component; 25 import org.apache.felix.scr.annotations.Component;
...@@ -35,8 +36,10 @@ import org.onosproject.store.service.EventuallyConsistentMapListener; ...@@ -35,8 +36,10 @@ import org.onosproject.store.service.EventuallyConsistentMapListener;
35 import org.onosproject.store.service.MultiValuedTimestamp; 36 import org.onosproject.store.service.MultiValuedTimestamp;
36 import org.onosproject.store.service.StorageService; 37 import org.onosproject.store.service.StorageService;
37 import org.onosproject.store.service.WallClockTimestamp; 38 import org.onosproject.store.service.WallClockTimestamp;
39 +import org.onosproject.vtnrsc.DefaultPortPair;
38 import org.onosproject.vtnrsc.PortPair; 40 import org.onosproject.vtnrsc.PortPair;
39 import org.onosproject.vtnrsc.PortPairId; 41 import org.onosproject.vtnrsc.PortPairId;
42 +import org.onosproject.vtnrsc.TenantId;
40 import org.onosproject.vtnrsc.portpair.PortPairEvent; 43 import org.onosproject.vtnrsc.portpair.PortPairEvent;
41 import org.onosproject.vtnrsc.portpair.PortPairListener; 44 import org.onosproject.vtnrsc.portpair.PortPairListener;
42 import org.onosproject.vtnrsc.portpair.PortPairService; 45 import org.onosproject.vtnrsc.portpair.PortPairService;
...@@ -72,7 +75,7 @@ public class PortPairManager extends AbstractListenerManager<PortPairEvent, Port ...@@ -72,7 +75,7 @@ public class PortPairManager extends AbstractListenerManager<PortPairEvent, Port
72 KryoNamespace.Builder serializer = KryoNamespace.newBuilder() 75 KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
73 .register(KryoNamespaces.API) 76 .register(KryoNamespaces.API)
74 .register(MultiValuedTimestamp.class) 77 .register(MultiValuedTimestamp.class)
75 - .register(PortPair.class); 78 + .register(PortPair.class, PortPairId.class, UUID.class, DefaultPortPair.class, TenantId.class);
76 79
77 portPairStore = storageService.<PortPairId, PortPair>eventuallyConsistentMapBuilder() 80 portPairStore = storageService.<PortPairId, PortPair>eventuallyConsistentMapBuilder()
78 .withName("portpairstore") 81 .withName("portpairstore")
......
...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
19 import static org.slf4j.LoggerFactory.getLogger; 19 import static org.slf4j.LoggerFactory.getLogger;
20 20
21 import java.util.Collections; 21 import java.util.Collections;
22 +import java.util.UUID;
22 23
23 import org.apache.felix.scr.annotations.Activate; 24 import org.apache.felix.scr.annotations.Activate;
24 import org.apache.felix.scr.annotations.Component; 25 import org.apache.felix.scr.annotations.Component;
...@@ -35,8 +36,11 @@ import org.onosproject.store.service.EventuallyConsistentMapListener; ...@@ -35,8 +36,11 @@ import org.onosproject.store.service.EventuallyConsistentMapListener;
35 import org.onosproject.store.service.MultiValuedTimestamp; 36 import org.onosproject.store.service.MultiValuedTimestamp;
36 import org.onosproject.store.service.StorageService; 37 import org.onosproject.store.service.StorageService;
37 import org.onosproject.store.service.WallClockTimestamp; 38 import org.onosproject.store.service.WallClockTimestamp;
39 +import org.onosproject.vtnrsc.DefaultPortPairGroup;
38 import org.onosproject.vtnrsc.PortPairGroup; 40 import org.onosproject.vtnrsc.PortPairGroup;
39 import org.onosproject.vtnrsc.PortPairGroupId; 41 import org.onosproject.vtnrsc.PortPairGroupId;
42 +import org.onosproject.vtnrsc.PortPairId;
43 +import org.onosproject.vtnrsc.TenantId;
40 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupEvent; 44 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupEvent;
41 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener; 45 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener;
42 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; 46 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
...@@ -71,7 +75,8 @@ public class PortPairGroupManager extends AbstractListenerManager<PortPairGroupE ...@@ -71,7 +75,8 @@ public class PortPairGroupManager extends AbstractListenerManager<PortPairGroupE
71 KryoNamespace.Builder serializer = KryoNamespace.newBuilder() 75 KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
72 .register(KryoNamespaces.API) 76 .register(KryoNamespaces.API)
73 .register(MultiValuedTimestamp.class) 77 .register(MultiValuedTimestamp.class)
74 - .register(PortPairGroup.class); 78 + .register(PortPairGroup.class, PortPairGroupId.class, UUID.class, DefaultPortPairGroup.class,
79 + TenantId.class, PortPairId.class);
75 80
76 portPairGroupStore = storageService 81 portPairGroupStore = storageService
77 .<PortPairGroupId, PortPairGroup>eventuallyConsistentMapBuilder() 82 .<PortPairGroupId, PortPairGroup>eventuallyConsistentMapBuilder()
......
1 +/*
2 + * Copyright 2014-2015 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 + */
16 +package org.onosproject.vtnweb.resources;
17 +
18 +import static com.google.common.base.Preconditions.checkNotNull;
19 +import static org.onlab.util.Tools.nullIsNotFound;
20 +
21 +import java.util.Set;
22 +
23 +import javax.ws.rs.Consumes;
24 +import javax.ws.rs.GET;
25 +import javax.ws.rs.Path;
26 +import javax.ws.rs.PathParam;
27 +import javax.ws.rs.Produces;
28 +import javax.ws.rs.core.MediaType;
29 +import javax.ws.rs.core.Response;
30 +
31 +import org.onosproject.codec.CodecContext;
32 +import org.onosproject.rest.AbstractWebResource;
33 +import org.onosproject.vtnrsc.LoadBalanceId;
34 +import org.onosproject.vtnrsc.PortChain;
35 +import org.onosproject.vtnrsc.PortChainId;
36 +import org.onosproject.vtnrsc.portchain.PortChainService;
37 +
38 +import com.fasterxml.jackson.databind.node.ObjectNode;
39 +
40 +/**
41 + * Query and program port chain.
42 + */
43 +
44 +@Path("portChainDeviceMap")
45 +public class PortChainDeviceMapWebResource extends AbstractWebResource {
46 +
47 + public static final String PORT_CHAIN_NOT_FOUND = "Port chain not found";
48 + public static final String PORT_CHAIN_ID_EXIST = "Port chain exists";
49 + public static final String PORT_CHAIN_ID_NOT_EXIST = "Port chain does not exist with identifier";
50 +
51 + private static final String NAME = "name";
52 + private static final String ID = "id";
53 + private static final String CLASSIFIERS = "classifiers";
54 + private static final String FORWARDERS = "forwarders";
55 + private static final String LOADBALANCEID = "loadBalanceId";
56 +
57 + /**
58 + * Get details of a specified port chain id.
59 + *
60 + * @param id port chain id
61 + * @return 200 OK, 404 if given identifier does not exist
62 + */
63 + @GET
64 + @Path("{chain_id}")
65 + @Produces(MediaType.APPLICATION_JSON)
66 + @Consumes(MediaType.APPLICATION_JSON)
67 + public Response getPortChainDeviceMap(@PathParam("chain_id") String id) {
68 +
69 + PortChain portChain = nullIsNotFound(get(PortChainService.class).getPortChain(PortChainId.of(id)),
70 + PORT_CHAIN_NOT_FOUND);
71 + ObjectNode result = mapper().createObjectNode();
72 + result.set("portChainDeviceMap", encode(portChain, this));
73 +
74 + return ok(result.toString()).build();
75 + }
76 +
77 + private ObjectNode encode(PortChain portChain, CodecContext context) {
78 + checkNotNull(portChain, "portChain cannot be null");
79 + ObjectNode result = context.mapper().createObjectNode();
80 + result.put(ID, portChain.portChainId().toString())
81 + .put(NAME, portChain.name());
82 +
83 + Set<LoadBalanceId> loadBalanceIds = portChain.getLoadBalancePathMapKeys();
84 + for (LoadBalanceId id : loadBalanceIds) {
85 + result.put(LOADBALANCEID, id.toString())
86 + .put(CLASSIFIERS, portChain.getSfcClassifiers(id).toString())
87 + .put(FORWARDERS, portChain.getSfcForwarders(id).toString());
88 + }
89 + return result;
90 + }
91 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.vtnweb.resources;
17 +
18 +import static org.onlab.util.Tools.nullIsNotFound;
19 +
20 +import javax.ws.rs.Consumes;
21 +import javax.ws.rs.GET;
22 +import javax.ws.rs.Path;
23 +import javax.ws.rs.PathParam;
24 +import javax.ws.rs.Produces;
25 +import javax.ws.rs.core.MediaType;
26 +import javax.ws.rs.core.Response;
27 +
28 +import org.onosproject.rest.AbstractWebResource;
29 +import org.onosproject.vtnrsc.PortChainId;
30 +import org.onosproject.vtnrsc.ServiceFunctionGroup;
31 +import org.onosproject.vtnrsc.portchainsfmap.PortChainSfMapService;
32 +
33 +import com.fasterxml.jackson.databind.node.ArrayNode;
34 +import com.fasterxml.jackson.databind.node.ObjectNode;
35 +
36 +/**
37 + * Query service function and load details by port chain.
38 + */
39 +
40 +@Path("portChainSfMap")
41 +public class PortChainSfMapWebResource extends AbstractWebResource {
42 +
43 + public static final String PORT_CHAIN_NOT_FOUND = "Port chain not found";
44 + public static final String PORT_CHAIN_ID_EXIST = "Port chain exists";
45 + public static final String PORT_CHAIN_ID_NOT_EXIST = "Port chain does not exist with identifier";
46 +
47 + /**
48 + * Get service function details of a specified port chain id.
49 + *
50 + * @param id port chain id
51 + * @return 200 OK, 404 if given identifier does not exist
52 + */
53 + @GET
54 + @Path("{chainId}")
55 + @Produces(MediaType.APPLICATION_JSON)
56 + @Consumes(MediaType.APPLICATION_JSON)
57 + public Response getPortChainSfMap(@PathParam("chainId") String id) {
58 +
59 + Iterable<ServiceFunctionGroup> serviceFunctionGroups = nullIsNotFound(get(PortChainSfMapService.class)
60 + .getServiceFunctions(PortChainId.of(id)),
61 + PORT_CHAIN_NOT_FOUND);
62 + ObjectNode result = mapper().createObjectNode();
63 + ArrayNode portChainSfMap = result.putArray("portChainSfMap");
64 + if (serviceFunctionGroups != null) {
65 + for (final ServiceFunctionGroup serviceFunctionGroup : serviceFunctionGroups) {
66 + portChainSfMap.add(codec(ServiceFunctionGroup.class).encode(serviceFunctionGroup, this));
67 + }
68 + }
69 + return ok(result.toString()).build();
70 + }
71 +}
...@@ -35,7 +35,9 @@ public class VtnWebApplication extends AbstractWebApplication { ...@@ -35,7 +35,9 @@ public class VtnWebApplication extends AbstractWebApplication {
35 PortPairWebResource.class, 35 PortPairWebResource.class,
36 FloatingIpWebResource.class, 36 FloatingIpWebResource.class,
37 RouterWebResource.class, 37 RouterWebResource.class,
38 - ClassifierWebResource.class); 38 + ClassifierWebResource.class,
39 + PortChainSfMapWebResource.class,
40 + PortChainDeviceMapWebResource.class);
39 } 41 }
40 } 42 }
41 43
......
...@@ -80,8 +80,10 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { ...@@ -80,8 +80,10 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
80 resultBuilder.setProtocol(protocol); 80 resultBuilder.setProtocol(protocol);
81 } 81 }
82 82
83 - int priority = (json.get(PRIORITY)).asInt(); 83 + if (json.get(PRIORITY) != null && !(json.get(PRIORITY)).asText().equals("null")) {
84 - resultBuilder.setPriority(priority); 84 + int priority = (json.get(PRIORITY)).asInt();
85 + resultBuilder.setPriority(priority);
86 + }
85 87
86 int minSrcPortRange = (json.get(MIN_SRC_PORT_RANGE)).asInt(); 88 int minSrcPortRange = (json.get(MIN_SRC_PORT_RANGE)).asInt();
87 resultBuilder.setMinSrcPortRange(minSrcPortRange); 89 resultBuilder.setMinSrcPortRange(minSrcPortRange);
......
1 /* 1 /*
2 - * Copyright 2015-present Open Networking Laboratory 2 + * Copyright 2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,8 +13,32 @@ ...@@ -13,8 +13,32 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +package org.onosproject.vtnweb.web;
17 +
18 +
19 +import static com.google.common.base.Preconditions.checkNotNull;
20 +
21 +import org.onosproject.codec.CodecContext;
22 +import org.onosproject.codec.JsonCodec;
23 +import org.onosproject.vtnrsc.ServiceFunctionGroup;
24 +
25 +import com.fasterxml.jackson.databind.node.ObjectNode;
16 26
17 /** 27 /**
18 - * SFC Service manager for interacting with SFC. 28 + * Service function JSON codec.
19 */ 29 */
20 -package org.onosproject.sfc.forwarder.impl; 30 +public final class ServiceFunctionCodec extends JsonCodec<ServiceFunctionGroup> {
31 +
32 + private static final String NAME = "name";
33 + private static final String DESCRIPTION = "description";
34 + private static final String PORT_PAIR_LOAD = "port_pair_load";
35 + @Override
36 + public ObjectNode encode(ServiceFunctionGroup serviceFunction, CodecContext context) {
37 + checkNotNull(serviceFunction, "service cannot be null");
38 + ObjectNode result = context.mapper().createObjectNode()
39 + .put(NAME, serviceFunction.name())
40 + .put(DESCRIPTION, serviceFunction.description())
41 + .put(PORT_PAIR_LOAD, serviceFunction.portPairLoadMap().toString());
42 + return result;
43 + }
44 +}
......
...@@ -25,6 +25,7 @@ import org.onosproject.vtnrsc.FlowClassifier; ...@@ -25,6 +25,7 @@ import org.onosproject.vtnrsc.FlowClassifier;
25 import org.onosproject.vtnrsc.PortChain; 25 import org.onosproject.vtnrsc.PortChain;
26 import org.onosproject.vtnrsc.PortPair; 26 import org.onosproject.vtnrsc.PortPair;
27 import org.onosproject.vtnrsc.PortPairGroup; 27 import org.onosproject.vtnrsc.PortPairGroup;
28 +import org.onosproject.vtnrsc.ServiceFunctionGroup;
28 import org.slf4j.Logger; 29 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory; 30 import org.slf4j.LoggerFactory;
30 31
...@@ -45,7 +46,7 @@ public class VtnCodecRegistrator { ...@@ -45,7 +46,7 @@ public class VtnCodecRegistrator {
45 codecService.registerCodec(PortPairGroup.class, new PortPairGroupCodec()); 46 codecService.registerCodec(PortPairGroup.class, new PortPairGroupCodec());
46 codecService.registerCodec(FlowClassifier.class, new FlowClassifierCodec()); 47 codecService.registerCodec(FlowClassifier.class, new FlowClassifierCodec());
47 codecService.registerCodec(PortChain.class, new PortChainCodec()); 48 codecService.registerCodec(PortChain.class, new PortChainCodec());
48 - 49 + codecService.registerCodec(ServiceFunctionGroup.class, new ServiceFunctionCodec());
49 log.info("Started"); 50 log.info("Started");
50 } 51 }
51 52
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.vtnweb.resources;
17 +
18 +import static org.easymock.EasyMock.anyObject;
19 +import static org.easymock.EasyMock.createMock;
20 +import static org.easymock.EasyMock.expect;
21 +import static org.easymock.EasyMock.replay;
22 +import static org.hamcrest.Matchers.is;
23 +import static org.hamcrest.Matchers.notNullValue;
24 +import static org.junit.Assert.assertThat;
25 +
26 +import java.util.HashSet;
27 +import java.util.List;
28 +import java.util.Objects;
29 +import java.util.Set;
30 +
31 +import javax.ws.rs.client.WebTarget;
32 +
33 +import org.junit.After;
34 +import org.junit.Before;
35 +import org.junit.Test;
36 +import org.onlab.osgi.ServiceDirectory;
37 +import org.onlab.osgi.TestServiceDirectory;
38 +import org.onlab.rest.BaseResource;
39 +import org.onosproject.codec.CodecService;
40 +import org.onosproject.net.DeviceId;
41 +import org.onosproject.vtnrsc.FiveTuple;
42 +import org.onosproject.vtnrsc.FlowClassifierId;
43 +import org.onosproject.vtnrsc.LoadBalanceId;
44 +import org.onosproject.vtnrsc.PortChain;
45 +import org.onosproject.vtnrsc.PortChainId;
46 +import org.onosproject.vtnrsc.PortPairGroupId;
47 +import org.onosproject.vtnrsc.PortPairId;
48 +import org.onosproject.vtnrsc.TenantId;
49 +import org.onosproject.vtnrsc.portchain.PortChainService;
50 +import org.onosproject.vtnweb.web.SfcCodecContext;
51 +
52 +import com.eclipsesource.json.Json;
53 +import com.eclipsesource.json.JsonObject;
54 +import com.google.common.collect.ImmutableList;
55 +import com.google.common.collect.Lists;
56 +
57 +/**
58 + * Unit tests for port chain device map REST APIs.
59 + */
60 +public class PortChainDeviceMapResourceTest extends VtnResourceTest {
61 +
62 + final PortChainService portChainService = createMock(PortChainService.class);
63 +
64 + PortChainId portChainId1 = PortChainId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
65 + TenantId tenantId1 = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5");
66 + private final List<PortPairGroupId> portPairGroupList1 = Lists.newArrayList();
67 + private final List<FlowClassifierId> flowClassifierList1 = Lists.newArrayList();
68 +
69 + final MockPortChain portChain1 = new MockPortChain(portChainId1, tenantId1, "portChain1",
70 + "Mock port chain", portPairGroupList1,
71 + flowClassifierList1);
72 +
73 + /**
74 + * Mock class for a port chain.
75 + */
76 + private static class MockPortChain implements PortChain {
77 +
78 + private final PortChainId portChainId;
79 + private final TenantId tenantId;
80 + private final String name;
81 + private final String description;
82 + private final List<PortPairGroupId> portPairGroupList;
83 + private final List<FlowClassifierId> flowClassifierList;
84 +
85 + public MockPortChain(PortChainId portChainId, TenantId tenantId,
86 + String name, String description,
87 + List<PortPairGroupId> portPairGroupList,
88 + List<FlowClassifierId> flowClassifierList) {
89 +
90 + this.portChainId = portChainId;
91 + this.tenantId = tenantId;
92 + this.name = name;
93 + this.description = description;
94 + this.portPairGroupList = portPairGroupList;
95 + this.flowClassifierList = flowClassifierList;
96 + }
97 +
98 + @Override
99 + public PortChainId portChainId() {
100 + return portChainId;
101 + }
102 +
103 + @Override
104 + public TenantId tenantId() {
105 + return tenantId;
106 + }
107 +
108 + @Override
109 + public String name() {
110 + return name;
111 + }
112 +
113 + @Override
114 + public String description() {
115 + return description;
116 + }
117 +
118 + @Override
119 + public List<PortPairGroupId> portPairGroups() {
120 + return ImmutableList.copyOf(portPairGroupList);
121 + }
122 +
123 + @Override
124 + public List<FlowClassifierId> flowClassifiers() {
125 + return ImmutableList.copyOf(flowClassifierList);
126 + }
127 +
128 + @Override
129 + public boolean exactMatch(PortChain portChain) {
130 + return this.equals(portChain) &&
131 + Objects.equals(this.portChainId, portChain.portChainId()) &&
132 + Objects.equals(this.tenantId, portChain.tenantId());
133 + }
134 +
135 + @Override
136 + public void addLoadBalancePath(FiveTuple fiveTuple, LoadBalanceId id, List<PortPairId> path) {
137 + }
138 +
139 + @Override
140 + public LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple) {
141 + return null;
142 + }
143 +
144 + @Override
145 + public Set<FiveTuple> getLoadBalanceIdMapKeys() {
146 + return null;
147 + }
148 +
149 + @Override
150 + public List<PortPairId> getLoadBalancePath(LoadBalanceId id) {
151 + return null;
152 + }
153 +
154 + @Override
155 + public List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple) {
156 + return null;
157 + }
158 +
159 + @Override
160 + public LoadBalanceId matchPath(List<PortPairId> path) {
161 + return null;
162 + }
163 +
164 + @Override
165 + public int getLoadBalancePathSize() {
166 + return 0;
167 + }
168 +
169 + @Override
170 + public void addSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) {
171 + }
172 +
173 + @Override
174 + public void addSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) {
175 + }
176 +
177 + @Override
178 + public void removeSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) {
179 + }
180 +
181 + @Override
182 + public void removeSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) {
183 + }
184 +
185 + @Override
186 + public List<DeviceId> getSfcClassifiers(LoadBalanceId id) {
187 + DeviceId deviceId1 = DeviceId.deviceId("of:000000000000001");
188 + List<DeviceId> classifierList = Lists.newArrayList();
189 + classifierList.add(deviceId1);
190 + return classifierList;
191 + }
192 +
193 + @Override
194 + public List<DeviceId> getSfcForwarders(LoadBalanceId id) {
195 + DeviceId deviceId1 = DeviceId.deviceId("of:000000000000002");
196 + DeviceId deviceId2 = DeviceId.deviceId("of:000000000000003");
197 + List<DeviceId> forwarderList = Lists.newArrayList();
198 + forwarderList.add(deviceId1);
199 + forwarderList.add(deviceId2);
200 + return forwarderList;
201 + }
202 +
203 + @Override
204 + public Set<LoadBalanceId> getLoadBalancePathMapKeys() {
205 + LoadBalanceId id = LoadBalanceId.of((byte) 1);
206 + Set<LoadBalanceId> set = new HashSet<LoadBalanceId>();
207 + set.add(id);
208 + return set;
209 + }
210 +
211 + @Override
212 + public PortChain oldPortChain() {
213 + return null;
214 + }
215 + }
216 +
217 + /**
218 + * Sets up the global values for all the tests.
219 + */
220 + @Before
221 + public void setUpTest() {
222 + SfcCodecContext context = new SfcCodecContext();
223 + ServiceDirectory testDirectory = new TestServiceDirectory()
224 + .add(PortChainService.class, portChainService)
225 + .add(CodecService.class, context.codecManager());
226 + BaseResource.setServiceDirectory(testDirectory);
227 + }
228 +
229 + /**
230 + * Cleans up.
231 + */
232 + @After
233 + public void tearDownTest() {
234 + }
235 +
236 + /**
237 + * Tests the result of a rest api GET for port chain id.
238 + */
239 + @Test
240 + public void testGetPortChainDeviceMap() {
241 +
242 + expect(portChainService.getPortChain(anyObject())).andReturn(portChain1).anyTimes();
243 + replay(portChainService);
244 +
245 + final WebTarget wt = target();
246 + final String response = wt.path("portChainDeviceMap/1278dcd4-459f-62ed-754b-87fc5e4a6751").request()
247 + .get(String.class);
248 + final JsonObject result = Json.parse(response).asObject();
249 + assertThat(result, notNullValue());
250 + assertThat(result.names().get(0), is("portChainDeviceMap"));
251 +
252 + }
253 +}
...@@ -15,10 +15,29 @@ ...@@ -15,10 +15,29 @@
15 */ 15 */
16 package org.onosproject.vtnweb.resources; 16 package org.onosproject.vtnweb.resources;
17 17
18 -import com.eclipsesource.json.Json; 18 +import static org.easymock.EasyMock.anyObject;
19 -import com.eclipsesource.json.JsonObject; 19 +import static org.easymock.EasyMock.createMock;
20 -import com.google.common.collect.ImmutableList; 20 +import static org.easymock.EasyMock.expect;
21 -import com.google.common.collect.Lists; 21 +import static org.easymock.EasyMock.replay;
22 +import static org.hamcrest.Matchers.containsString;
23 +import static org.hamcrest.Matchers.is;
24 +import static org.hamcrest.Matchers.notNullValue;
25 +import static org.junit.Assert.assertThat;
26 +import static org.junit.Assert.fail;
27 +
28 +import java.io.InputStream;
29 +import java.net.HttpURLConnection;
30 +import java.util.HashSet;
31 +import java.util.List;
32 +import java.util.Objects;
33 +import java.util.Set;
34 +
35 +import javax.ws.rs.NotFoundException;
36 +import javax.ws.rs.client.Entity;
37 +import javax.ws.rs.client.WebTarget;
38 +import javax.ws.rs.core.MediaType;
39 +import javax.ws.rs.core.Response;
40 +
22 import org.junit.After; 41 import org.junit.After;
23 import org.junit.Before; 42 import org.junit.Before;
24 import org.junit.Test; 43 import org.junit.Test;
...@@ -38,28 +57,10 @@ import org.onosproject.vtnrsc.TenantId; ...@@ -38,28 +57,10 @@ import org.onosproject.vtnrsc.TenantId;
38 import org.onosproject.vtnrsc.portchain.PortChainService; 57 import org.onosproject.vtnrsc.portchain.PortChainService;
39 import org.onosproject.vtnweb.web.SfcCodecContext; 58 import org.onosproject.vtnweb.web.SfcCodecContext;
40 59
41 -import javax.ws.rs.NotFoundException; 60 +import com.eclipsesource.json.Json;
42 -import javax.ws.rs.client.Entity; 61 +import com.eclipsesource.json.JsonObject;
43 -import javax.ws.rs.client.WebTarget; 62 +import com.google.common.collect.ImmutableList;
44 -import javax.ws.rs.core.MediaType; 63 +import com.google.common.collect.Lists;
45 -import javax.ws.rs.core.Response;
46 -import java.io.InputStream;
47 -import java.net.HttpURLConnection;
48 -import java.util.HashSet;
49 -import java.util.List;
50 -import java.util.Objects;
51 -import java.util.Optional;
52 -import java.util.Set;
53 -
54 -import static org.easymock.EasyMock.anyObject;
55 -import static org.easymock.EasyMock.createMock;
56 -import static org.easymock.EasyMock.expect;
57 -import static org.easymock.EasyMock.replay;
58 -import static org.hamcrest.Matchers.containsString;
59 -import static org.hamcrest.Matchers.is;
60 -import static org.hamcrest.Matchers.notNullValue;
61 -import static org.junit.Assert.assertThat;
62 -import static org.junit.Assert.fail;
63 64
64 /** 65 /**
65 * Unit tests for port chain REST APIs. 66 * Unit tests for port chain REST APIs.
...@@ -165,7 +166,7 @@ public class PortChainResourceTest extends VtnResourceTest { ...@@ -165,7 +166,7 @@ public class PortChainResourceTest extends VtnResourceTest {
165 } 166 }
166 167
167 @Override 168 @Override
168 - public Optional<LoadBalanceId> matchPath(List<PortPairId> path) { 169 + public LoadBalanceId matchPath(List<PortPairId> path) {
169 return null; 170 return null;
170 } 171 }
171 172
...@@ -204,6 +205,11 @@ public class PortChainResourceTest extends VtnResourceTest { ...@@ -204,6 +205,11 @@ public class PortChainResourceTest extends VtnResourceTest {
204 public Set<LoadBalanceId> getLoadBalancePathMapKeys() { 205 public Set<LoadBalanceId> getLoadBalancePathMapKeys() {
205 return null; 206 return null;
206 } 207 }
208 +
209 + @Override
210 + public PortChain oldPortChain() {
211 + return null;
212 + }
207 } 213 }
208 214
209 /** 215 /**
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.vtnweb.resources;
17 +
18 +import static org.easymock.EasyMock.anyObject;
19 +import static org.easymock.EasyMock.createMock;
20 +import static org.easymock.EasyMock.expect;
21 +import static org.easymock.EasyMock.replay;
22 +import static org.hamcrest.Matchers.is;
23 +import static org.hamcrest.Matchers.notNullValue;
24 +import static org.junit.Assert.assertThat;
25 +
26 +import java.util.List;
27 +import java.util.Map;
28 +import java.util.concurrent.ConcurrentHashMap;
29 +
30 +import javax.ws.rs.client.WebTarget;
31 +
32 +import org.junit.After;
33 +import org.junit.Before;
34 +import org.junit.Test;
35 +import org.onlab.osgi.ServiceDirectory;
36 +import org.onlab.osgi.TestServiceDirectory;
37 +import org.onlab.rest.BaseResource;
38 +import org.onosproject.codec.CodecService;
39 +import org.onosproject.vtnrsc.PortPairId;
40 +import org.onosproject.vtnrsc.ServiceFunctionGroup;
41 +import org.onosproject.vtnrsc.portchainsfmap.PortChainSfMapService;
42 +import org.onosproject.vtnweb.web.SfcCodecContext;
43 +
44 +import com.eclipsesource.json.Json;
45 +import com.eclipsesource.json.JsonObject;
46 +import com.google.common.collect.Lists;
47 +
48 +/**
49 + * Unit tests for port chain sf map REST APIs.
50 + */
51 +public class PortChainSfMapResourceTest extends VtnResourceTest {
52 +
53 + final PortChainSfMapService portChainSfMapService = createMock(PortChainSfMapService.class);
54 +
55 + String name1 = "Firewall";
56 + String description1 = "Firewall service function";
57 + Map<PortPairId, Integer> portPairLoadMap1 = new ConcurrentHashMap<>();
58 +
59 + ServiceFunctionGroup serviceFunction1 = new ServiceFunctionGroup(name1, description1,
60 + portPairLoadMap1);
61 +
62 + /**
63 + * Sets up the global values for all the tests.
64 + */
65 + @Before
66 + public void setUpTest() {
67 + SfcCodecContext context = new SfcCodecContext();
68 + ServiceDirectory testDirectory = new TestServiceDirectory()
69 + .add(PortChainSfMapService.class, portChainSfMapService)
70 + .add(CodecService.class, context.codecManager());
71 + BaseResource.setServiceDirectory(testDirectory);
72 + }
73 +
74 + /**
75 + * Cleans up.
76 + */
77 + @After
78 + public void tearDownTest() {
79 + }
80 +
81 + /**
82 + * Tests the result of a rest api GET for port chain id.
83 + */
84 + @Test
85 + public void testGetPortChainId() {
86 +
87 + final List<ServiceFunctionGroup> serviceFunctions = Lists.newArrayList();
88 + serviceFunctions.add(serviceFunction1);
89 +
90 + expect(portChainSfMapService.getServiceFunctions(anyObject())).andReturn(serviceFunctions).anyTimes();
91 + replay(portChainSfMapService);
92 +
93 + final WebTarget wt = target();
94 + final String response = wt.path("portChainSfMap/1278dcd4-459f-62ed-754b-87fc5e4a6751").request()
95 + .get(String.class);
96 + final JsonObject result = Json.parse(response).asObject();
97 + assertThat(result, notNullValue());
98 + assertThat(result.names().get(0), is("portChainSfMap"));
99 + }
100 +}
...@@ -136,6 +136,10 @@ public class PortPairGroupResourceTest extends VtnResourceTest { ...@@ -136,6 +136,10 @@ public class PortPairGroupResourceTest extends VtnResourceTest {
136 Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) && 136 Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) &&
137 Objects.equals(this.tenantId, portPairGroup.tenantId()); 137 Objects.equals(this.tenantId, portPairGroup.tenantId());
138 } 138 }
139 +
140 + @Override
141 + public void resetLoad() {
142 + }
139 } 143 }
140 144
141 /** 145 /**
......
...@@ -38,6 +38,7 @@ public class ExtensionSelectorType { ...@@ -38,6 +38,7 @@ public class ExtensionSelectorType {
38 NICIRA_MATCH_NSH_CH2(3), 38 NICIRA_MATCH_NSH_CH2(3),
39 NICIRA_MATCH_NSH_CH3(4), 39 NICIRA_MATCH_NSH_CH3(4),
40 NICIRA_MATCH_NSH_CH4(5), 40 NICIRA_MATCH_NSH_CH4(5),
41 + NICIRA_MATCH_ENCAP_ETH_TYPE(6),
41 OFDPA_MATCH_VLAN_VID(16), 42 OFDPA_MATCH_VLAN_VID(16),
42 BMV2_MATCH_PARAMS(128); 43 BMV2_MATCH_PARAMS(128);
43 44
......
...@@ -38,14 +38,29 @@ public final class ExtensionTreatmentType { ...@@ -38,14 +38,29 @@ public final class ExtensionTreatmentType {
38 NICIRA_MOV_ARP_SPA_TO_TPA(3), 38 NICIRA_MOV_ARP_SPA_TO_TPA(3),
39 NICIRA_MOV_ETH_SRC_TO_DST(4), 39 NICIRA_MOV_ETH_SRC_TO_DST(4),
40 NICIRA_MOV_IP_SRC_TO_DST(5), 40 NICIRA_MOV_IP_SRC_TO_DST(5),
41 + NICIRA_MOV_NSH_C1_TO_C1(6),
42 + NICIRA_MOV_NSH_C2_TO_C2(7),
43 + NICIRA_MOV_NSH_C3_TO_C3(8),
44 + NICIRA_MOV_NSH_C4_TO_C4(9),
45 + NICIRA_MOV_TUN_IPV4_DST_TO_TUN_IPV4_DST(10),
46 + NICIRA_MOV_TUN_ID_TO_TUN_ID(11),
47 + NICIRA_MOV_NSH_C2_TO_TUN_ID(12),
41 NICIRA_RESUBMIT_TABLE(14), 48 NICIRA_RESUBMIT_TABLE(14),
42 - NICIRA_SET_NSH_SPI(32), 49 + NICIRA_PUSH_NSH(38),
43 - NICIRA_SET_NSH_SI(33), 50 + NICIRA_POP_NSH(39),
44 - NICIRA_SET_NSH_CH1(34),
45 - NICIRA_SET_NSH_CH2(35),
46 - NICIRA_SET_NSH_CH3(36),
47 - NICIRA_SET_NSH_CH4(37),
48 OFDPA_SET_VLAN_ID(64), 51 OFDPA_SET_VLAN_ID(64),
52 + NICIRA_TUN_GPE_NP(111),
53 + NICIRA_SET_NSH_SPI(113),
54 + NICIRA_SET_NSH_SI(114),
55 + NICIRA_SET_NSH_CH1(115),
56 + NICIRA_SET_NSH_CH2(116),
57 + NICIRA_SET_NSH_CH3(117),
58 + NICIRA_SET_NSH_CH4(118),
59 + NICIRA_NSH_MDTYPE(119),
60 + NICIRA_NSH_NP(120),
61 + NICIRA_ENCAP_ETH_SRC(121),
62 + NICIRA_ENCAP_ETH_DST(122),
63 + NICIRA_ENCAP_ETH_TYPE(123),
49 BMV2_ACTION(128); 64 BMV2_ACTION(128);
50 65
51 private ExtensionTreatmentType type; 66 private ExtensionTreatmentType type;
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
15 */ 15 */
16 package org.onosproject.net.device; 16 package org.onosproject.net.device;
17 17
18 -import com.google.common.collect.FluentIterable; 18 +import java.util.Collections;
19 +import java.util.List;
19 20
20 import org.onosproject.net.Device; 21 import org.onosproject.net.Device;
21 import org.onosproject.net.Device.Type; 22 import org.onosproject.net.Device.Type;
...@@ -24,13 +25,31 @@ import org.onosproject.net.MastershipRole; ...@@ -24,13 +25,31 @@ import org.onosproject.net.MastershipRole;
24 import org.onosproject.net.Port; 25 import org.onosproject.net.Port;
25 import org.onosproject.net.PortNumber; 26 import org.onosproject.net.PortNumber;
26 27
27 -import java.util.Collections; 28 +import com.google.common.collect.FluentIterable;
28 -import java.util.List;
29 29
30 /** 30 /**
31 * Test adapter for device service. 31 * Test adapter for device service.
32 */ 32 */
33 public class DeviceServiceAdapter implements DeviceService { 33 public class DeviceServiceAdapter implements DeviceService {
34 +
35 + private List<Port> portList;
36 +
37 + /**
38 + * Constructor with port list.
39 + *
40 + * @param portList port list
41 + */
42 + public DeviceServiceAdapter(List<Port> portList) {
43 + this.portList = portList;
44 + }
45 +
46 + /**
47 + * Default constructor.
48 + */
49 + public DeviceServiceAdapter() {
50 +
51 + }
52 +
34 @Override 53 @Override
35 public int getDeviceCount() { 54 public int getDeviceCount() {
36 return 0; 55 return 0;
...@@ -59,7 +78,7 @@ public class DeviceServiceAdapter implements DeviceService { ...@@ -59,7 +78,7 @@ public class DeviceServiceAdapter implements DeviceService {
59 78
60 @Override 79 @Override
61 public List<Port> getPorts(DeviceId deviceId) { 80 public List<Port> getPorts(DeviceId deviceId) {
62 - return Collections.emptyList(); 81 + return portList;
63 } 82 }
64 83
65 @Override 84 @Override
......
...@@ -38,7 +38,6 @@ public class DefaultMoveExtensionTreatment extends AbstractExtension ...@@ -38,7 +38,6 @@ public class DefaultMoveExtensionTreatment extends AbstractExtension
38 private ExtensionTreatmentType type; 38 private ExtensionTreatmentType type;
39 39
40 private final KryoNamespace appKryo = new KryoNamespace.Builder() 40 private final KryoNamespace appKryo = new KryoNamespace.Builder()
41 - .register(byte[].class)
42 .register(Map.class) 41 .register(Map.class)
43 .build("DefaultMoveExtensionTreatment"); 42 .build("DefaultMoveExtensionTreatment");
44 43
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import java.util.Objects;
20 +
21 +import org.onlab.packet.MacAddress;
22 +import org.onlab.util.KryoNamespace;
23 +import org.onosproject.net.flow.AbstractExtension;
24 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
25 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
26 +import org.onosproject.store.serializers.MacAddressSerializer;
27 +
28 +import com.google.common.base.MoreObjects;
29 +
30 +/**
31 + * Nicira EncapEthDst extension instruction to set encapsulated eth destination.
32 + */
33 +public class NiciraEncapEthDst extends AbstractExtension implements ExtensionTreatment {
34 +
35 + private MacAddress encapEthDst;
36 +
37 + private final KryoNamespace appKryo = new KryoNamespace.Builder()
38 + .register(new MacAddressSerializer(), MacAddress.class).register(byte[].class).build();;
39 +
40 + /**
41 + * Creates a new nshEncapEthDst instruction.
42 + */
43 + NiciraEncapEthDst() {
44 + }
45 +
46 + /**
47 + * Creates a new encapEthDst instruction with given mac address.
48 + *
49 + * @param encapEthDst encapsulated ethernet destination
50 + */
51 + public NiciraEncapEthDst(MacAddress encapEthDst) {
52 + this.encapEthDst = encapEthDst;
53 + }
54 +
55 + /**
56 + * Gets the encapEthDst.
57 + *
58 + * @return encapEthDst
59 + */
60 + public MacAddress encapEthDst() {
61 + return encapEthDst;
62 + }
63 +
64 + @Override
65 + public ExtensionTreatmentType type() {
66 + return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_DST.type();
67 + }
68 +
69 + @Override
70 + public void deserialize(byte[] data) {
71 + encapEthDst = appKryo.deserialize(data);
72 + }
73 +
74 + @Override
75 + public byte[] serialize() {
76 + return appKryo.serialize(encapEthDst);
77 + }
78 +
79 + @Override
80 + public int hashCode() {
81 + return Objects.hash(encapEthDst);
82 + }
83 +
84 + @Override
85 + public boolean equals(Object obj) {
86 + if (this == obj) {
87 + return true;
88 + }
89 + if (obj instanceof NiciraEncapEthDst) {
90 + NiciraEncapEthDst that = (NiciraEncapEthDst) obj;
91 + return Objects.equals(encapEthDst, that.encapEthDst);
92 +
93 + }
94 + return false;
95 + }
96 +
97 + @Override
98 + public String toString() {
99 + return MoreObjects.toStringHelper(getClass()).add("encapEthDst", encapEthDst).toString();
100 + }
101 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import java.util.Objects;
20 +
21 +import org.onlab.packet.MacAddress;
22 +import org.onlab.util.KryoNamespace;
23 +import org.onosproject.net.flow.AbstractExtension;
24 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
25 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
26 +import org.onosproject.store.serializers.MacAddressSerializer;
27 +
28 +import com.google.common.base.MoreObjects;
29 +
30 +/**
31 + * Nicira EncapEthSrc extension instruction to set encapsulated eth source.
32 + */
33 +public class NiciraEncapEthSrc extends AbstractExtension implements ExtensionTreatment {
34 +
35 + private MacAddress encapEthSrc;
36 +
37 + private final KryoNamespace appKryo = new KryoNamespace.Builder()
38 + .register(new MacAddressSerializer(), MacAddress.class).register(byte[].class).build();;
39 +
40 + /**
41 + * Creates a new nshEncapEthSrc instruction.
42 + */
43 + NiciraEncapEthSrc() {
44 + }
45 +
46 + /**
47 + * Creates a new encapEthSrc instruction with given mac address.
48 + *
49 + * @param encapEthSrc encapsulated ethernet source
50 + */
51 + public NiciraEncapEthSrc(MacAddress encapEthSrc) {
52 + this.encapEthSrc = encapEthSrc;
53 + }
54 +
55 + /**
56 + * Gets the encapEthSrc.
57 + *
58 + * @return encapEthSrc
59 + */
60 + public MacAddress encapEthSrc() {
61 + return encapEthSrc;
62 + }
63 +
64 + @Override
65 + public ExtensionTreatmentType type() {
66 + return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_SRC.type();
67 + }
68 +
69 + @Override
70 + public void deserialize(byte[] data) {
71 + encapEthSrc = appKryo.deserialize(data);
72 + }
73 +
74 + @Override
75 + public byte[] serialize() {
76 + return appKryo.serialize(encapEthSrc);
77 + }
78 +
79 + @Override
80 + public int hashCode() {
81 + return Objects.hash(encapEthSrc);
82 + }
83 +
84 + @Override
85 + public boolean equals(Object obj) {
86 + if (this == obj) {
87 + return true;
88 + }
89 + if (obj instanceof NiciraEncapEthSrc) {
90 + NiciraEncapEthSrc that = (NiciraEncapEthSrc) obj;
91 + return Objects.equals(encapEthSrc, that.encapEthSrc);
92 +
93 + }
94 + return false;
95 + }
96 +
97 + @Override
98 + public String toString() {
99 + return MoreObjects.toStringHelper(getClass()).add("encapEthSrc", encapEthSrc).toString();
100 + }
101 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import java.util.Objects;
20 +
21 +import org.onlab.util.KryoNamespace;
22 +import org.onosproject.net.flow.AbstractExtension;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
24 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +/**
29 + * Nicira EncapEthType extension instruction to set encapsulated eth type.
30 + */
31 +public class NiciraEncapEthType extends AbstractExtension implements ExtensionTreatment {
32 +
33 + private short encapEthType;
34 +
35 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36 +
37 + /**
38 + * Creates a new nshEncapEthType instruction.
39 + */
40 + NiciraEncapEthType() {
41 + encapEthType = (short) 0;
42 + }
43 +
44 + /**
45 + * Creates a new nshEncapEthType instruction with given eth type.
46 + *
47 + * @param encapEthType encapsulated ethernet type
48 + */
49 + public NiciraEncapEthType(short encapEthType) {
50 + this.encapEthType = encapEthType;
51 + }
52 +
53 + /**
54 + * Gets the encapEthType.
55 + *
56 + * @return encapEthType
57 + */
58 + public short encapEthType() {
59 + return encapEthType;
60 + }
61 +
62 + @Override
63 + public ExtensionTreatmentType type() {
64 + return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_TYPE.type();
65 + }
66 +
67 + @Override
68 + public void deserialize(byte[] data) {
69 + encapEthType = (short) (appKryo.deserialize(data));
70 + }
71 +
72 + @Override
73 + public byte[] serialize() {
74 + return appKryo.serialize(encapEthType);
75 + }
76 +
77 + @Override
78 + public int hashCode() {
79 + return Objects.hash(encapEthType);
80 + }
81 +
82 + @Override
83 + public boolean equals(Object obj) {
84 + if (this == obj) {
85 + return true;
86 + }
87 + if (obj instanceof NiciraEncapEthType) {
88 + NiciraEncapEthType that = (NiciraEncapEthType) obj;
89 + return Objects.equals(encapEthType, that.encapEthType);
90 +
91 + }
92 + return false;
93 + }
94 +
95 + @Override
96 + public String toString() {
97 + return MoreObjects.toStringHelper(getClass()).add("encapEthType", encapEthType).toString();
98 + }
99 +}
...@@ -18,13 +18,22 @@ package org.onosproject.driver.extensions; ...@@ -18,13 +18,22 @@ package org.onosproject.driver.extensions;
18 18
19 import com.fasterxml.jackson.databind.node.ObjectNode; 19 import com.fasterxml.jackson.databind.node.ObjectNode;
20 import org.onosproject.codec.CodecContext; 20 import org.onosproject.codec.CodecContext;
21 +import org.onosproject.net.NshServiceIndex;
22 +import org.onosproject.net.NshServicePathId;
21 import org.onosproject.net.behaviour.ExtensionSelectorResolver; 23 import org.onosproject.net.behaviour.ExtensionSelectorResolver;
22 import org.onosproject.net.driver.AbstractHandlerBehaviour; 24 import org.onosproject.net.driver.AbstractHandlerBehaviour;
23 import org.onosproject.net.flow.criteria.ExtensionSelector; 25 import org.onosproject.net.flow.criteria.ExtensionSelector;
24 import org.onosproject.net.flow.criteria.ExtensionSelectorType; 26 import org.onosproject.net.flow.criteria.ExtensionSelectorType;
25 import org.onosproject.openflow.controller.ExtensionSelectorInterpreter; 27 import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
26 import org.projectfloodlight.openflow.protocol.OFFactory; 28 import org.projectfloodlight.openflow.protocol.OFFactory;
29 +import org.projectfloodlight.openflow.protocol.match.MatchField;
27 import org.projectfloodlight.openflow.protocol.oxm.OFOxm; 30 import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
31 +import org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType;
32 +import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsi;
33 +import org.projectfloodlight.openflow.protocol.oxm.OFOxmNsp;
34 +import org.projectfloodlight.openflow.types.U16;
35 +import org.projectfloodlight.openflow.types.U32;
36 +import org.projectfloodlight.openflow.types.U8;
28 37
29 /** 38 /**
30 * Interpreter for Nicira OpenFlow selector extensions. 39 * Interpreter for Nicira OpenFlow selector extensions.
...@@ -53,17 +62,28 @@ public class NiciraExtensionSelectorInterpreter ...@@ -53,17 +62,28 @@ public class NiciraExtensionSelectorInterpreter
53 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) { 62 if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) {
54 return true; 63 return true;
55 } 64 }
65 + if (extensionSelectorType.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE
66 + .type())) {
67 + return true;
68 + }
56 return false; 69 return false;
57 } 70 }
58 71
59 @Override 72 @Override
60 public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { 73 public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) {
61 ExtensionSelectorType type = extensionSelector.type(); 74 ExtensionSelectorType type = extensionSelector.type();
75 +
62 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) { 76 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) {
63 - // TODO 77 + NiciraMatchNshSpi niciraNshSpi = (NiciraMatchNshSpi) extensionSelector;
78 + return factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId()));
64 } 79 }
65 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) { 80 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) {
66 - // TODO 81 + NiciraMatchNshSi niciraNshSi = (NiciraMatchNshSi) extensionSelector;
82 + return factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex()));
83 + }
84 + if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) {
85 + NiciraMatchEncapEthType niciraEncapEthType = (NiciraMatchEncapEthType) extensionSelector;
86 + return factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType()));
67 } 87 }
68 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) { 88 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) {
69 // TODO 89 // TODO
...@@ -82,6 +102,20 @@ public class NiciraExtensionSelectorInterpreter ...@@ -82,6 +102,20 @@ public class NiciraExtensionSelectorInterpreter
82 102
83 @Override 103 @Override
84 public ExtensionSelector mapOxm(OFOxm<?> oxm) { 104 public ExtensionSelector mapOxm(OFOxm<?> oxm) {
105 +
106 + if (oxm.getMatchField() == MatchField.NSP) {
107 + OFOxmNsp oxmField = (OFOxmNsp) oxm;
108 + return new NiciraMatchNshSpi(NshServicePathId.of(oxmField.getValue().getRaw()));
109 + }
110 + if (oxm.getMatchField() == MatchField.NSI) {
111 + OFOxmNsi oxmField = (OFOxmNsi) oxm;
112 + return new NiciraMatchNshSi(NshServiceIndex.of(oxmField.getValue().getRaw()));
113 + }
114 + if (oxm.getMatchField() == MatchField.ENCAP_ETH_TYPE) {
115 + OFOxmEncapEthType oxmField = (OFOxmEncapEthType) oxm;
116 + return new NiciraMatchEncapEthType(oxmField.getValue().getRaw());
117 + }
118 +
85 return null; 119 return null;
86 } 120 }
87 121
...@@ -93,6 +127,9 @@ public class NiciraExtensionSelectorInterpreter ...@@ -93,6 +127,9 @@ public class NiciraExtensionSelectorInterpreter
93 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) { 127 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) {
94 return new NiciraMatchNshSi(); 128 return new NiciraMatchNshSi();
95 } 129 }
130 + if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) {
131 + return new NiciraMatchEncapEthType();
132 + }
96 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type()) 133 if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())
97 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type()) 134 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())
98 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type()) 135 || type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import java.util.Objects;
20 +
21 +import org.onlab.util.KryoNamespace;
22 +import org.onosproject.net.flow.AbstractExtension;
23 +import org.onosproject.net.flow.criteria.ExtensionSelector;
24 +import org.onosproject.net.flow.criteria.ExtensionSelectorType;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +/**
29 + * Nicira EncapEthType extension selector to set encapsulated eth type.
30 + */
31 +public class NiciraMatchEncapEthType extends AbstractExtension implements ExtensionSelector {
32 +
33 + private short encapEthType;
34 +
35 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36 +
37 + /**
38 + * Creates a new nshEncapEthType selector.
39 + */
40 + NiciraMatchEncapEthType() {
41 + encapEthType = (short) 0;
42 + }
43 +
44 + /**
45 + * Creates a new nshEncapEthType selector with given eth type.
46 + *
47 + * @param encapEthType encapsulated ethernet type
48 + */
49 + public NiciraMatchEncapEthType(short encapEthType) {
50 + this.encapEthType = encapEthType;
51 + }
52 +
53 + /**
54 + * Gets the encapEthType.
55 + *
56 + * @return encapEthType
57 + */
58 + public short encapEthType() {
59 + return encapEthType;
60 + }
61 +
62 + @Override
63 + public ExtensionSelectorType type() {
64 + return ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type();
65 + }
66 +
67 + @Override
68 + public void deserialize(byte[] data) {
69 + encapEthType = (short) (appKryo.deserialize(data));
70 + }
71 +
72 + @Override
73 + public byte[] serialize() {
74 + return appKryo.serialize(encapEthType);
75 + }
76 +
77 + @Override
78 + public int hashCode() {
79 + return Objects.hash(encapEthType);
80 + }
81 +
82 + @Override
83 + public boolean equals(Object obj) {
84 + if (this == obj) {
85 + return true;
86 + }
87 + if (obj instanceof NiciraMatchEncapEthType) {
88 + NiciraMatchEncapEthType that = (NiciraMatchEncapEthType) obj;
89 + return Objects.equals(encapEthType, that.encapEthType);
90 +
91 + }
92 + return false;
93 + }
94 +
95 + @Override
96 + public String toString() {
97 + return MoreObjects.toStringHelper(getClass()).add("encapEthType", encapEthType).toString();
98 + }
99 +}
...@@ -97,4 +97,88 @@ public final class NiciraMoveTreatmentFactory { ...@@ -97,4 +97,88 @@ public final class NiciraMoveTreatmentFactory {
97 ExtensionTreatmentType.ExtensionTreatmentTypes 97 ExtensionTreatmentType.ExtensionTreatmentTypes
98 .NICIRA_MOV_IP_SRC_TO_DST.type()); 98 .NICIRA_MOV_IP_SRC_TO_DST.type());
99 } 99 }
100 +
101 + public static ExtensionTreatment createNiciraMovNshC1ToC1() {
102 + int srcOfs = 0;
103 + int dstOfs = 0;
104 + int nBits = 32;
105 + int srcC1 = 0x0001e604;
106 + int dstC1 = 0x0001e604;
107 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcC1,
108 + dstC1,
109 + ExtensionTreatmentType.ExtensionTreatmentTypes
110 + .NICIRA_MOV_NSH_C1_TO_C1.type());
111 + }
112 +
113 + public static ExtensionTreatment createNiciraMovNshC2ToC2() {
114 + int srcOfs = 0;
115 + int dstOfs = 0;
116 + int nBits = 32;
117 + int srcC2 = 0x0001e804;
118 + int dstC2 = 0x0001e804;
119 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcC2,
120 + dstC2,
121 + ExtensionTreatmentType.ExtensionTreatmentTypes
122 + .NICIRA_MOV_NSH_C2_TO_C2.type());
123 + }
124 +
125 + public static ExtensionTreatment createNiciraMovNshC3ToC3() {
126 + int srcOfs = 0;
127 + int dstOfs = 0;
128 + int nBits = 32;
129 + int srcC3 = 0x0001ea04;
130 + int dstC3 = 0x0001ea04;
131 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcC3,
132 + dstC3,
133 + ExtensionTreatmentType.ExtensionTreatmentTypes
134 + .NICIRA_MOV_NSH_C3_TO_C3.type());
135 + }
136 +
137 + public static ExtensionTreatment createNiciraMovNshC4ToC4() {
138 + int srcOfs = 0;
139 + int dstOfs = 0;
140 + int nBits = 32;
141 + int srcC4 = 0x0001ec04;
142 + int dstC4 = 0x0001ec04;
143 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcC4,
144 + dstC4,
145 + ExtensionTreatmentType.ExtensionTreatmentTypes
146 + .NICIRA_MOV_NSH_C4_TO_C4.type());
147 + }
148 +
149 + public static ExtensionTreatment createNiciraMovTunDstToTunDst() {
150 + int srcOfs = 0;
151 + int dstOfs = 0;
152 + int nBits = 32;
153 + int srcTunIpv4Dst = 0x00014004;
154 + int dstTunIpv4Dst = 0x00014004;
155 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcTunIpv4Dst,
156 + dstTunIpv4Dst,
157 + ExtensionTreatmentType.ExtensionTreatmentTypes
158 + .NICIRA_MOV_TUN_IPV4_DST_TO_TUN_IPV4_DST.type());
159 + }
160 +
161 + public static ExtensionTreatment createNiciraMovTunIdToTunId() {
162 + int srcOfs = 0;
163 + int dstOfs = 0;
164 + int nBits = 64;
165 + int srcTunId = 0x12008;
166 + int dstTunId = 0x12008; // 0x80004c08;
167 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcTunId,
168 + dstTunId,
169 + ExtensionTreatmentType.ExtensionTreatmentTypes
170 + .NICIRA_MOV_TUN_ID_TO_TUN_ID.type());
171 + }
172 +
173 + public static ExtensionTreatment createNiciraMovNshC2ToTunId() {
174 + int srcOfs = 0;
175 + int dstOfs = 0;
176 + int nBits = 32;
177 + int srcC2 = 0x0001e804;
178 + int dstTunId = 0x80004c08;
179 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, srcC2,
180 + dstTunId,
181 + ExtensionTreatmentType.ExtensionTreatmentTypes
182 + .NICIRA_MOV_NSH_C2_TO_TUN_ID.type());
183 + }
100 } 184 }
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import java.util.Objects;
20 +
21 +import org.onlab.util.KryoNamespace;
22 +import org.onosproject.net.flow.AbstractExtension;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
24 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +/**
29 + * Nicira nshMdType extension instruction.
30 + */
31 +public class NiciraNshMdType extends AbstractExtension implements ExtensionTreatment {
32 +
33 + private byte nshMdType;
34 +
35 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36 +
37 + /**
38 + * Creates a new nshMdType instruction.
39 + */
40 + NiciraNshMdType() {
41 + nshMdType = (byte) 0;
42 + }
43 +
44 + /**
45 + * Creates a new nshMdType instruction with given nsh md type.
46 + *
47 + * @param nshMdType nsh md type
48 + */
49 + public NiciraNshMdType(byte nshMdType) {
50 + this.nshMdType = nshMdType;
51 + }
52 +
53 + /**
54 + * Gets the nsh md type.
55 + *
56 + * @return nshMdType
57 + */
58 + public byte nshMdType() {
59 + return nshMdType;
60 + }
61 +
62 + @Override
63 + public ExtensionTreatmentType type() {
64 + return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_MDTYPE.type();
65 + }
66 +
67 + @Override
68 + public void deserialize(byte[] data) {
69 + nshMdType = (byte) (appKryo.deserialize(data));
70 + }
71 +
72 + @Override
73 + public byte[] serialize() {
74 + return appKryo.serialize(nshMdType);
75 + }
76 +
77 + @Override
78 + public int hashCode() {
79 + return Objects.hash(nshMdType);
80 + }
81 +
82 + @Override
83 + public boolean equals(Object obj) {
84 + if (this == obj) {
85 + return true;
86 + }
87 + if (obj instanceof NiciraNshMdType) {
88 + NiciraNshMdType that = (NiciraNshMdType) obj;
89 + return Objects.equals(nshMdType, that.nshMdType);
90 +
91 + }
92 + return false;
93 + }
94 +
95 + @Override
96 + public String toString() {
97 + return MoreObjects.toStringHelper(getClass()).add("nshMdType", nshMdType).toString();
98 + }
99 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import java.util.Objects;
20 +
21 +import org.onlab.util.KryoNamespace;
22 +import org.onosproject.net.flow.AbstractExtension;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
24 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +/**
29 + * Nicira nshNp extension instruction to set next protocol value in nsh header.
30 + */
31 +public class NiciraNshNp extends AbstractExtension implements ExtensionTreatment {
32 +
33 + private byte nshNp;
34 +
35 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36 +
37 + /**
38 + * Creates a new nshNp instruction.
39 + */
40 + NiciraNshNp() {
41 + nshNp = (byte) 0;
42 + }
43 +
44 + /**
45 + * Creates a new nshNp instruction with given nsh np.
46 + *
47 + * @param nshNp nsh next protocol value
48 + */
49 + public NiciraNshNp(byte nshNp) {
50 + this.nshNp = nshNp;
51 + }
52 +
53 + /**
54 + * Gets the nsh np.
55 + *
56 + * @return nshNp
57 + */
58 + public byte nshNp() {
59 + return nshNp;
60 + }
61 +
62 + @Override
63 + public ExtensionTreatmentType type() {
64 + return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_NP.type();
65 + }
66 +
67 + @Override
68 + public void deserialize(byte[] data) {
69 + nshNp = (byte) (appKryo.deserialize(data));
70 + }
71 +
72 + @Override
73 + public byte[] serialize() {
74 + return appKryo.serialize(nshNp);
75 + }
76 +
77 + @Override
78 + public int hashCode() {
79 + return Objects.hash(nshNp);
80 + }
81 +
82 + @Override
83 + public boolean equals(Object obj) {
84 + if (this == obj) {
85 + return true;
86 + }
87 + if (obj instanceof NiciraNshNp) {
88 + NiciraNshNp that = (NiciraNshNp) obj;
89 + return Objects.equals(nshNp, that.nshNp);
90 +
91 + }
92 + return false;
93 + }
94 +
95 + @Override
96 + public String toString() {
97 + return MoreObjects.toStringHelper(getClass()).add("nshNp", nshNp).toString();
98 + }
99 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import org.onlab.util.KryoNamespace;
20 +import org.onosproject.net.flow.AbstractExtension;
21 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
22 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
23 +
24 +/**
25 + * Nicira pop nsh extension instruction.
26 + */
27 +public class NiciraPopNsh extends AbstractExtension implements ExtensionTreatment {
28 +
29 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
30 +
31 + /**
32 + * Creates a new pop nsh instruction.
33 + */
34 + public NiciraPopNsh() {
35 + }
36 +
37 + @Override
38 + public ExtensionTreatmentType type() {
39 + return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_POP_NSH.type();
40 + }
41 +
42 + @Override
43 + public void deserialize(byte[] data) {
44 + }
45 +
46 + @Override
47 + public byte[] serialize() {
48 + return appKryo.serialize(0);
49 + }
50 +
51 + @Override
52 + public int hashCode() {
53 + return 1;
54 + }
55 +
56 + @Override
57 + public boolean equals(Object obj) {
58 + if (this == obj) {
59 + return true;
60 + }
61 + if (obj instanceof NiciraPopNsh) {
62 + return true;
63 + }
64 + return false;
65 + }
66 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import org.onlab.util.KryoNamespace;
20 +import org.onosproject.net.flow.AbstractExtension;
21 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
22 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
23 +
24 +/**
25 + * Nicira push nsh extension instruction.
26 + */
27 +public class NiciraPushNsh extends AbstractExtension implements ExtensionTreatment {
28 +
29 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
30 +
31 + /**
32 + * Creates a new push nsh instruction.
33 + */
34 + public NiciraPushNsh() {
35 +
36 + }
37 +
38 + @Override
39 + public ExtensionTreatmentType type() {
40 + return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_PUSH_NSH.type();
41 + }
42 +
43 + @Override
44 + public void deserialize(byte[] data) {
45 + }
46 +
47 + @Override
48 + public byte[] serialize() {
49 + return appKryo.serialize(0);
50 + }
51 +
52 + @Override
53 + public int hashCode() {
54 + return 1;
55 + }
56 +
57 + @Override
58 + public boolean equals(Object obj) {
59 + if (this == obj) {
60 + return true;
61 + }
62 + if (obj instanceof NiciraPushNsh) {
63 + return true;
64 + }
65 + return false;
66 + }
67 +}
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.driver.extensions; 17 package org.onosproject.driver.extensions;
18 18
19 +import java.util.Map;
19 import java.util.Objects; 20 import java.util.Objects;
20 21
21 import org.onlab.util.KryoNamespace; 22 import org.onlab.util.KryoNamespace;
...@@ -25,6 +26,7 @@ import org.onosproject.net.flow.instructions.ExtensionTreatment; ...@@ -25,6 +26,7 @@ import org.onosproject.net.flow.instructions.ExtensionTreatment;
25 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 26 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
26 27
27 import com.google.common.base.MoreObjects; 28 import com.google.common.base.MoreObjects;
29 +import com.google.common.collect.Maps;
28 30
29 /** 31 /**
30 * Nicira set NSH Context header extension instruction. 32 * Nicira set NSH Context header extension instruction.
...@@ -74,12 +76,17 @@ public class NiciraSetNshContextHeader extends AbstractExtension implements ...@@ -74,12 +76,17 @@ public class NiciraSetNshContextHeader extends AbstractExtension implements
74 76
75 @Override 77 @Override
76 public void deserialize(byte[] data) { 78 public void deserialize(byte[] data) {
77 - nshCh = NshContextHeader.of(appKryo.deserialize(data)); 79 + Map<String, Object> values = appKryo.deserialize(data);
80 + nshCh = (NshContextHeader) values.get("nshCh");
81 + type = (ExtensionTreatmentType) values.get("type");
78 } 82 }
79 83
80 @Override 84 @Override
81 public byte[] serialize() { 85 public byte[] serialize() {
82 - return appKryo.serialize(nshCh.nshContextHeader()); 86 + Map<String, Object> values = Maps.newHashMap();
87 + values.put("nshCh", nshCh);
88 + values.put("type", type);
89 + return appKryo.serialize(values);
83 } 90 }
84 91
85 @Override 92 @Override
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import java.util.Objects;
20 +
21 +import org.onlab.util.KryoNamespace;
22 +import org.onosproject.net.flow.AbstractExtension;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatment;
24 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +/**
29 + * Nicira tunnel gpe next protocol extension instruction to tunGpeNp value.
30 + */
31 +public class NiciraTunGpeNp extends AbstractExtension implements ExtensionTreatment {
32 +
33 + private byte tunGpeNp;
34 +
35 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36 +
37 + /**
38 + * Creates a new NiciraTunGpeNp instruction.
39 + */
40 + NiciraTunGpeNp() {
41 + tunGpeNp = (byte) 0;
42 + }
43 +
44 + /**
45 + * Creates a new NiciraTunGpeNp instruction with given value.
46 + *
47 + * @param tunGpeNp tunnel gpe next protocol value
48 + */
49 + public NiciraTunGpeNp(byte tunGpeNp) {
50 + this.tunGpeNp = tunGpeNp;
51 + }
52 +
53 + /**
54 + * Gets the tunGpeNp.
55 + *
56 + * @return tunGpeNp
57 + */
58 + public byte tunGpeNp() {
59 + return tunGpeNp;
60 + }
61 +
62 + @Override
63 + public ExtensionTreatmentType type() {
64 + return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_TUN_GPE_NP.type();
65 + }
66 +
67 + @Override
68 + public void deserialize(byte[] data) {
69 + tunGpeNp = (byte) (appKryo.deserialize(data));
70 + }
71 +
72 + @Override
73 + public byte[] serialize() {
74 + return appKryo.serialize(tunGpeNp);
75 + }
76 +
77 + @Override
78 + public int hashCode() {
79 + return Objects.hash(tunGpeNp);
80 + }
81 +
82 + @Override
83 + public boolean equals(Object obj) {
84 + if (this == obj) {
85 + return true;
86 + }
87 + if (obj instanceof NiciraTunGpeNp) {
88 + NiciraTunGpeNp that = (NiciraTunGpeNp) obj;
89 + return Objects.equals(tunGpeNp, that.tunGpeNp);
90 +
91 + }
92 + return false;
93 + }
94 +
95 + @Override
96 + public String toString() {
97 + return MoreObjects.toStringHelper(getClass()).add("tunGpeNp", tunGpeNp).toString();
98 + }
99 +}
...@@ -70,6 +70,8 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline ...@@ -70,6 +70,8 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline
70 protected DeviceService deviceService; 70 protected DeviceService deviceService;
71 private static final int TIME_OUT = 0; 71 private static final int TIME_OUT = 0;
72 private static final int CLASSIFIER_TABLE = 0; 72 private static final int CLASSIFIER_TABLE = 0;
73 + private static final int ENCAP_OUTPUT_TABLE = 4;
74 + private static final int TUN_SEND_TABLE = 7;
73 private static final int ARP_TABLE = 10; 75 private static final int ARP_TABLE = 10;
74 private static final int DNAT_TABLE = 20; 76 private static final int DNAT_TABLE = 20;
75 private static final int L3FWD_TABLE = 30; 77 private static final int L3FWD_TABLE = 30;
...@@ -278,7 +280,23 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline ...@@ -278,7 +280,23 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline
278 280
279 private Collection<FlowRule> processVersatile(ForwardingObjective fwd) { 281 private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
280 log.debug("Processing versatile forwarding objective"); 282 log.debug("Processing versatile forwarding objective");
281 - return Collections.emptyList(); 283 + TrafficSelector selector = fwd.selector();
284 + TrafficTreatment tb = fwd.treatment();
285 + FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority())
286 + .forDevice(deviceId).withSelector(selector).withTreatment(tb).makeTemporary(TIME_OUT);
287 + ruleBuilder.withPriority(fwd.priority());
288 + if (fwd.priority() == 100) {
289 + ruleBuilder.forTable(ENCAP_OUTPUT_TABLE);
290 + } else if (fwd.priority() == 200) {
291 + ruleBuilder.forTable(TUN_SEND_TABLE);
292 + } else {
293 + ruleBuilder.forTable(CLASSIFIER_TABLE);
294 + }
295 +
296 + if (fwd.permanent()) {
297 + ruleBuilder.makePermanent();
298 + }
299 + return Collections.singletonList(ruleBuilder.build());
282 } 300 }
283 301
284 private Collection<FlowRule> processSpecific(ForwardingObjective fwd) { 302 private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
......
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +import org.onlab.packet.MacAddress;
24 +
25 +import com.google.common.testing.EqualsTester;
26 +
27 +/**
28 + * Unit tests for NiciraEncapEthDstTest class.
29 + */
30 +public class NiciraEncapEthDstTest {
31 +
32 + private final MacAddress mac1 = MacAddress.valueOf("fa:16:3e:da:45:23");
33 + private final MacAddress mac2 = MacAddress.valueOf("fa:16:3e:f3:d1:fe");
34 +
35 + /**
36 + * Checks the operation of equals() methods.
37 + */
38 + @Test
39 + public void testEquals() {
40 + final NiciraEncapEthDst encapEthDst1 = new NiciraEncapEthDst(mac1);
41 + final NiciraEncapEthDst sameAsEncapEthDst1 = new NiciraEncapEthDst(mac1);
42 + final NiciraEncapEthDst encapEthDst2 = new NiciraEncapEthDst(mac2);
43 +
44 + new EqualsTester().addEqualityGroup(encapEthDst1, sameAsEncapEthDst1).addEqualityGroup(encapEthDst2)
45 + .testEquals();
46 + }
47 +
48 + /**
49 + * Checks the construction of a NiciraEncapEthDstTest object.
50 + */
51 + @Test
52 + public void testConstruction() {
53 + final NiciraEncapEthDst encapEthDst1 = new NiciraEncapEthDst(mac1);
54 + assertThat(encapEthDst1, is(notNullValue()));
55 + assertThat(encapEthDst1.encapEthDst(), is(mac1));
56 + }
57 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +import org.onlab.packet.MacAddress;
24 +
25 +import com.google.common.testing.EqualsTester;
26 +
27 +/**
28 + * Unit tests for NiciraEncapEthSrcTest class.
29 + */
30 +public class NiciraEncapEthSrcTest {
31 +
32 + private final MacAddress mac1 = MacAddress.valueOf("fa:16:3e:11:00:01");
33 + private final MacAddress mac2 = MacAddress.valueOf("fa:16:3e:22:00:02");
34 +
35 + /**
36 + * Checks the operation of equals() methods.
37 + */
38 + @Test
39 + public void testEquals() {
40 + final NiciraEncapEthDst encapEthDst1 = new NiciraEncapEthDst(mac1);
41 + final NiciraEncapEthDst sameAsEncapEthDst1 = new NiciraEncapEthDst(mac1);
42 + final NiciraEncapEthDst encapEthDst2 = new NiciraEncapEthDst(mac2);
43 +
44 + new EqualsTester().addEqualityGroup(encapEthDst1, sameAsEncapEthDst1).addEqualityGroup(encapEthDst2)
45 + .testEquals();
46 + }
47 +
48 + /**
49 + * Checks the construction of a NiciraEncapEthSrcTest object.
50 + */
51 + @Test
52 + public void testConstruction() {
53 +
54 + final NiciraEncapEthDst encapEthDst1 = new NiciraEncapEthDst(mac1);
55 + assertThat(encapEthDst1, is(notNullValue()));
56 + assertThat(encapEthDst1.encapEthDst(), is(mac1));
57 + }
58 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +
24 +import com.google.common.testing.EqualsTester;
25 +
26 +/**
27 + * Unit tests for NiciraEncapEthType class.
28 + */
29 +public class NiciraEncapEthTypeTest {
30 + final short ethType1 = (short) 0x894f;
31 + final short ethType2 = (short) 0x800;
32 +
33 + /**
34 + * Checks the operation of equals() methods.
35 + */
36 + @Test
37 + public void testEquals() {
38 + final NiciraEncapEthType encapEthType1 = new NiciraEncapEthType(ethType1);
39 + final NiciraEncapEthType sameAsEncapEthType1 = new NiciraEncapEthType(ethType1);
40 + final NiciraEncapEthType encapEthType2 = new NiciraEncapEthType(ethType2);
41 +
42 + new EqualsTester().addEqualityGroup(encapEthType1, sameAsEncapEthType1).addEqualityGroup(encapEthType2)
43 + .testEquals();
44 + }
45 +
46 + /**
47 + * Checks the construction of a NiciraEncapEthType object.
48 + */
49 + @Test
50 + public void testConstruction() {
51 + final NiciraEncapEthType encapEthType = new NiciraEncapEthType(ethType1);
52 + assertThat(encapEthType, is(notNullValue()));
53 + assertThat(encapEthType.encapEthType(), is(ethType1));
54 + }
55 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +
24 +import com.google.common.testing.EqualsTester;
25 +
26 +/**
27 + * Unit tests for NiciraMatchEncapEthType class.
28 + */
29 +public class NiciraMatchEncapEthTypeTest {
30 + final short ethType1 = (short) 0x894f;
31 + final short ethType2 = (short) 0x800;
32 +
33 + /**
34 + * Checks the operation of equals() methods.
35 + */
36 + @Test
37 + public void testEquals() {
38 + final NiciraMatchEncapEthType encapEthType1 = new NiciraMatchEncapEthType(ethType1);
39 + final NiciraMatchEncapEthType sameAsEncapEthType1 = new NiciraMatchEncapEthType(ethType1);
40 + final NiciraMatchEncapEthType encapEthType2 = new NiciraMatchEncapEthType(ethType2);
41 +
42 + new EqualsTester().addEqualityGroup(encapEthType1, sameAsEncapEthType1).addEqualityGroup(encapEthType2)
43 + .testEquals();
44 + }
45 +
46 + /**
47 + * Checks the construction of a NiciraMatchEncapEthType object.
48 + */
49 + @Test
50 + public void testConstruction() {
51 + final NiciraMatchEncapEthType encapEthType = new NiciraMatchEncapEthType(ethType1);
52 + assertThat(encapEthType, is(notNullValue()));
53 + assertThat(encapEthType.encapEthType(), is(ethType1));
54 + }
55 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +
24 +import com.google.common.testing.EqualsTester;
25 +
26 +/**
27 + * Unit tests for NiciraNshMdType class.
28 + */
29 +public class NiciraNshMdTypeTest {
30 + final byte mdType1 = (byte) 1;
31 + final byte mdType2 = (byte) 2;
32 +
33 + /**
34 + * Checks the operation of equals() methods.
35 + */
36 + @Test
37 + public void testEquals() {
38 + final NiciraNshMdType nshMdType1 = new NiciraNshMdType(mdType1);
39 + final NiciraNshMdType sameAsnshMdType1 = new NiciraNshMdType(mdType1);
40 + final NiciraNshMdType nshMdType2 = new NiciraNshMdType(mdType2);
41 +
42 + new EqualsTester().addEqualityGroup(nshMdType1, sameAsnshMdType1).addEqualityGroup(nshMdType2)
43 + .testEquals();
44 + }
45 +
46 + /**
47 + * Checks the construction of a NiciraNshMdType object.
48 + */
49 + @Test
50 + public void testConstruction() {
51 + final NiciraNshMdType nshMdType = new NiciraNshMdType(mdType1);
52 + assertThat(nshMdType, is(notNullValue()));
53 + assertThat(nshMdType.nshMdType(), is(mdType1));
54 + }
55 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +
24 +import com.google.common.testing.EqualsTester;
25 +
26 +/**
27 + * Unit tests for NiciraNshNp class.
28 + */
29 +public class NiciraNshNpTest {
30 + final byte np1 = (byte) 1;
31 + final byte np2 = (byte) 4;
32 +
33 + /**
34 + * Checks the operation of equals() methods.
35 + */
36 + @Test
37 + public void testEquals() {
38 + final NiciraNshNp nshNp1 = new NiciraNshNp(np1);
39 + final NiciraNshNp sameAsNshNp1 = new NiciraNshNp(np1);
40 + final NiciraNshNp nshNp2 = new NiciraNshNp(np2);
41 +
42 + new EqualsTester().addEqualityGroup(nshNp1, sameAsNshNp1).addEqualityGroup(nshNp2)
43 + .testEquals();
44 + }
45 +
46 + /**
47 + * Checks the construction of a NiciraNshNp object.
48 + */
49 + @Test
50 + public void testConstruction() {
51 + final NiciraNshNp nshNp1 = new NiciraNshNp(np1);
52 + assertThat(nshNp1, is(notNullValue()));
53 + assertThat(nshNp1.nshNp(), is(np1));
54 + }
55 +}
1 +/*
2 + * Copyright 2016-present 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 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +
24 +import com.google.common.testing.EqualsTester;
25 +
26 +/**
27 + * Unit tests for NiciraTunGpeNp class.
28 + */
29 +public class NiciraTunGpeNpTest {
30 + final byte np1 = (byte) 1;
31 + final byte np2 = (byte) 2;
32 +
33 + /**
34 + * Checks the operation of equals() methods.
35 + */
36 + @Test
37 + public void testEquals() {
38 + final NiciraTunGpeNp tunGpeNp1 = new NiciraTunGpeNp(np1);
39 + final NiciraTunGpeNp sameAsTunGpeNp1 = new NiciraTunGpeNp(np1);
40 + final NiciraTunGpeNp tunGpeNp2 = new NiciraTunGpeNp(np2);
41 +
42 + new EqualsTester().addEqualityGroup(tunGpeNp1, sameAsTunGpeNp1).addEqualityGroup(tunGpeNp2)
43 + .testEquals();
44 + }
45 +
46 + /**
47 + * Checks the construction of a NiciraTunGpeNp object.
48 + */
49 + @Test
50 + public void testConstruction() {
51 + final NiciraTunGpeNp tunGpeNp1 = new NiciraTunGpeNp(np1);
52 + assertThat(tunGpeNp1, is(notNullValue()));
53 + assertThat(tunGpeNp1.tunGpeNp(), is(np1));
54 + }
55 +}
...@@ -511,6 +511,18 @@ public class FlowEntryBuilder { ...@@ -511,6 +511,18 @@ public class FlowEntryBuilder {
511 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort())); 511 builder.setUdpSrc(TpPort.tpPort(udpsrc.getValue().getPort()));
512 break; 512 break;
513 case TUNNEL_IPV4_DST: 513 case TUNNEL_IPV4_DST:
514 + case NSP:
515 + case NSI:
516 + case NSH_C1:
517 + case NSH_C2:
518 + case NSH_C3:
519 + case NSH_C4:
520 + case NSH_MDTYPE:
521 + case NSH_NP:
522 + case ENCAP_ETH_SRC:
523 + case ENCAP_ETH_DST:
524 + case ENCAP_ETH_TYPE:
525 + case TUN_GPE_NP:
514 if (treatmentInterpreter != null) { 526 if (treatmentInterpreter != null) {
515 try { 527 try {
516 builder.extension(treatmentInterpreter.mapAction(action), deviceId); 528 builder.extension(treatmentInterpreter.mapAction(action), deviceId);
...@@ -900,6 +912,36 @@ public class FlowEntryBuilder { ...@@ -900,6 +912,36 @@ public class FlowEntryBuilder {
900 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt()); 912 ip = Ip4Address.valueOf(match.get(MatchField.ARP_TPA).getInt());
901 builder.matchArpTpa(ip); 913 builder.matchArpTpa(ip);
902 break; 914 break;
915 + case NSP:
916 + if (selectorInterpreter != null) {
917 + try {
918 + OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSP);
919 + builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
920 + } catch (UnsupportedOperationException e) {
921 + log.debug(e.getMessage());
922 + }
923 + }
924 + break;
925 + case NSI:
926 + if (selectorInterpreter != null) {
927 + try {
928 + OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.NSI);
929 + builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
930 + } catch (UnsupportedOperationException e) {
931 + log.debug(e.getMessage());
932 + }
933 + }
934 + break;
935 + case ENCAP_ETH_TYPE:
936 + if (selectorInterpreter != null) {
937 + try {
938 + OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.ENCAP_ETH_TYPE);
939 + builder.extension(selectorInterpreter.mapOxm(oxm), deviceId);
940 + } catch (UnsupportedOperationException e) {
941 + log.debug(e.getMessage());
942 + }
943 + }
944 + break;
903 case MPLS_TC: 945 case MPLS_TC:
904 default: 946 default:
905 log.warn("Match type {} not yet implemented.", field.id); 947 log.warn("Match type {} not yet implemented.", field.id);
......