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