+.DS_Store
.idea/
target/
*.class
control.vm.network "private_network", ip: "#{control_ip}"
control.vm.network "private_network", ip: "#{neutron_ex_ip}", virtualbox__intnet: "mylocalnet"
control.vm.provider :virtualbox do |vb|
- vb.memory = 4096
- vb.cpus = 2
+ vb.memory = 6192
+ vb.cpus = 4
end
control.vm.provider "vmware_fusion" do |vf|
vf.vmx["memsize"] = "4096"
-PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/vagrant/devstack-scripts:/vagrant/devstack-scripts/tutorial"
+PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/vagrant/devstack-scripts:/vagrant/devstack-scripts/tutorial:/vagrant/devstack-scripts/sfc"
export ODL=192.168.50.1
sudo service rabbitmq-server restart
sudo service mysql restart
-sudo ovs-vsctl set-manager tcp:192.168.50.1:6640
+sudo ovs-vsctl set-manager tcp:$ODL:6640
sudo ovs-vsctl add-br br-int
-sudo ovs-vsctl set-controller tcp:192.168.50.1:6653
+sudo ovs-vsctl set-controller tcp:$ODL:6653
echo "Removing all logs to save space..."
sudo rm -rf /opt/stack/logs/*
quota_security_group_rules=200
quota_security_groups=200
quota_volumes=100
-#scheduler_default_filters = AllHostsFilter
+scheduler_default_filters = AllHostsFilter
[quota]
skip_isolated_core_check=true
max_cores=128
echo "Installing wget..."
apt-get install -y wget >/dev/null
+# Install vim
+echo "Installing vim..."
+apt-get install -y vim >/dev/null
+
+# Setup paths
+echo "Copying paths and ODL environment variable from .../devstack-scripts/environment to /etc/environment"
+cp /vagrant/devstack-scripts/environment /etc/environment
+source /etc/environment
+
# Install the PuppetLabs repo
echo "Configuring PuppetLabs repo..."
repo_deb_path=$(mktemp)
[[local|localrc]]
-#enable_plugin networking-odl https://github.com/stackforge/networking-odl
-enable_plugin networking-odl https://github.com/flavio-fernandes/networking-odl lithiumkilo
+enable_plugin networking-odl https://github.com/openstack/networking-odl stable/kilo
+
LOGFILE=stack.sh.log
LOG_COLOR=False
[[local|localrc]]
-#enable_plugin networking-odl https://github.com/stackforge/networking-odl
-#enable_plugin networking-odl /vagrant/x/networking-odl.git plugin
-enable_plugin networking-odl https://github.com/flavio-fernandes/networking-odl lithiumkilo
+enable_plugin networking-odl https://github.com/openstack/networking-odl stable/kilo
LOGFILE=stack.sh.log
SCREEN_LOGDIR=/opt/stack/data/log
--- /dev/null
+#!/usr/bin/python
+import socket
+import requests,json
+from requests.auth import HTTPBasicAuth
+import sys
+import os
+from subprocess import check_output
+from infrastructure_config import *
+
+
+DEFAULT_PORT='8181'
+USERNAME='admin'
+PASSWORD='admin'
+
+def get(host, port, uri):
+ url='http://'+host+":"+port+uri
+ #print url
+ r = requests.get(url, auth=HTTPBasicAuth(USERNAME, PASSWORD))
+ jsondata=json.loads(r.text)
+ return jsondata
+
+
+def get_rsps_uri():
+ return "/restconf/operational/rendered-service-path:rendered-service-paths"
+
+def doCmd(cmd):
+ listcmd=cmd.split()
+ print check_output(listcmd)
+
+if __name__ == "__main__":
+ # Launch main menu
+
+
+ # Some sensible defaults
+ controller=os.environ.get('ODL')
+ if controller == None:
+ sys.exit("No controller set.")
+ #else:
+ #print "Contacting controller at %s" % controller
+
+ resp=get(controller,DEFAULT_PORT,get_rsps_uri())
+ if len(resp['rendered-service-paths']) > 0:
+ paths=resp['rendered-service-paths']['rendered-service-path']
+
+ nsps=[]
+ for path in paths:
+ nsps.append(path['path-id'])
+ if len(nsps) > 0:
+ sw_index=int(socket.gethostname().split("gbpsfc",1)[1])-1
+ if sw_index in range(0,len(switches)+1):
+
+ controller=os.environ.get('ODL')
+ sw_type = switches[sw_index]['type']
+ sw_name = switches[sw_index]['name']
+ if sw_type == 'sf':
+ print "******************************"
+ print "Adding flows for %s as an SF." % sw_name
+ print "******************************"
+ doCmd('sudo /vagrant/demo-asymmetric-coexistence/sf-flows.sh %s' % min(nsps))
+
--- /dev/null
+# Config for switches, tunnelIP is the local IP address.
+switches = [
+ {'name': 'sw1',
+ 'type': 'gbp',
+ 'dpid': '1'},
+ {'name': 'sw2',
+ 'type': 'gbp',
+ 'dpid': '2'},
+ {'name': 'sw3',
+ 'type': 'sf',
+ 'dpid': '3'},
+ {'name': 'sw4',
+ 'type': 'gbp',
+ 'dpid': '4'},
+ {'name': 'sw5',
+ 'type': 'sf',
+ 'dpid': '5'},
+ {'name': 'sw6',
+ 'type': 'none',
+ 'dpid': '6'}
+ ]
+
+defaultContainerImage='alagalah/odlpoc_ovs230'
+
+#Note that tenant name and endpointGroup name come from policy_config.py
+
+hosts = [{'name': 'h35_2',
+ 'mac': '00:00:00:00:35:02',
+ 'ip': '10.0.35.2/24',
+ 'switch': 'sw1'},
+ {'name': 'h35_3',
+ 'ip': '10.0.35.3/24',
+ 'mac': '00:00:00:00:35:03',
+ 'switch': 'sw2'},
+ {'name': 'h35_4',
+ 'ip': '10.0.35.4/24',
+ 'mac': '00:00:00:00:35:04',
+ 'switch': 'sw4'},
+ {'name': 'h36_2',
+ 'ip': '10.0.36.2/24',
+ 'mac': '00:00:00:00:36:02',
+ 'switch': 'sw1'},
+ {'name': 'h36_3',
+ 'ip': '10.0.36.3/24',
+ 'mac': '00:00:00:00:36:03',
+ 'switch': 'sw2'},
+ {'name': 'h36_4',
+ 'ip': '10.0.36.4/24',
+ 'mac': '00:00:00:00:36:04',
+ 'switch': 'sw4'}
+ ]
\ No newline at end of file
"name": "firewall-72",
"sff-sf-data-plane-locator": {
"sf-dpl-name": "2",
- "sff-dpl-name": "sfc-tun2"
+ "sff-dpl-name": "sw1-vxlangpe-0"
}
}
],
"sff-data-plane-locator": [
{
- "name": "sfc-tun2",
+ "name": "sw1-vxlangpe-0",
"data-plane-locator": {
"transport": "service-locator:vxlan-gpe",
"port": 6633,
"name": "dpi-74",
"sff-sf-data-plane-locator": {
"sf-dpl-name": "3",
- "sff-dpl-name": "sfc-tun4"
+ "sff-dpl-name": "sw2-vxlangpe-0"
}
}
],
"sff-data-plane-locator": [
{
- "name": "sfc-tun4",
+ "name": "sw2-vxlangpe-0",
"data-plane-locator": {
"transport": "service-locator:vxlan-gpe",
"port": 6633,
--- /dev/null
+#!/usr/bin/python
+import socket
+import requests,json
+from requests.auth import HTTPBasicAuth
+import sys
+import os
+from subprocess import check_output
+from infrastructure_config import *
+
+
+DEFAULT_PORT='8181'
+USERNAME='admin'
+PASSWORD='admin'
+
+def get(host, port, uri):
+ url='http://'+host+":"+port+uri
+ #print url
+ r = requests.get(url, auth=HTTPBasicAuth(USERNAME, PASSWORD))
+ jsondata=json.loads(r.text)
+ return jsondata
+
+
+def get_rsps_uri():
+ return "/restconf/operational/rendered-service-path:rendered-service-paths"
+
+def doCmd(cmd):
+ listcmd=cmd.split()
+ print check_output(listcmd)
+
+if __name__ == "__main__":
+ # Launch main menu
+
+
+ # Some sensible defaults
+ controller=os.environ.get('ODL')
+ if controller == None:
+ sys.exit("No controller set.")
+ #else:
+ #print "Contacting controller at %s" % controller
+
+ resp=get(controller,DEFAULT_PORT,get_rsps_uri())
+ if len(resp['rendered-service-paths']) > 0:
+ paths=resp['rendered-service-paths']['rendered-service-path']
+
+ nsps=[]
+ for path in paths:
+ nsps.append(path['path-id'])
+ if len(nsps) > 0:
+ sw_index=int(socket.gethostname().split("gbpsfc",1)[1])-1
+ if sw_index in range(0,len(switches)+1):
+
+ controller=os.environ.get('ODL')
+ sw_type = switches[sw_index]['type']
+ sw_name = switches[sw_index]['name']
+ if sw_type == 'sf':
+ print "******************************"
+ print "Adding flows for %s as an SF." % sw_name
+ print "******************************"
+ doCmd('sudo /vagrant/demo-symmetric-coexistence/sf-flows.sh %s' % min(nsps))
+
--- /dev/null
+# Config for switches, tunnelIP is the local IP address.
+switches = [
+ {'name': 'sw1',
+ 'type': 'gbp',
+ 'dpid': '1'},
+ {'name': 'sw2',
+ 'type': 'gbp',
+ 'dpid': '2'},
+ {'name': 'sw3',
+ 'type': 'sf',
+ 'dpid': '3'},
+ {'name': 'sw4',
+ 'type': 'gbp',
+ 'dpid': '4'},
+ {'name': 'sw5',
+ 'type': 'sf',
+ 'dpid': '5'},
+ {'name': 'sw6',
+ 'type': 'none',
+ 'dpid': '6'}
+ ]
+
+defaultContainerImage='alagalah/odlpoc_ovs230'
+
+#Note that tenant name and endpointGroup name come from policy_config.py
+
+hosts = [{'name': 'h35_2',
+ 'mac': '00:00:00:00:35:02',
+ 'ip': '10.0.35.2/24',
+ 'switch': 'sw1'},
+ {'name': 'h35_3',
+ 'ip': '10.0.35.3/24',
+ 'mac': '00:00:00:00:35:03',
+ 'switch': 'sw2'},
+ {'name': 'h35_4',
+ 'ip': '10.0.35.4/24',
+ 'mac': '00:00:00:00:35:04',
+ 'switch': 'sw4'},
+ {'name': 'h36_2',
+ 'ip': '10.0.36.2/24',
+ 'mac': '00:00:00:00:36:02',
+ 'switch': 'sw1'},
+ {'name': 'h36_3',
+ 'ip': '10.0.36.3/24',
+ 'mac': '00:00:00:00:36:03',
+ 'switch': 'sw2'},
+ {'name': 'h36_4',
+ 'ip': '10.0.36.4/24',
+ 'mac': '00:00:00:00:36:04',
+ 'switch': 'sw4'}
+ ]
"name": "firewall-72",
"sff-sf-data-plane-locator": {
"sf-dpl-name": "2",
- "sff-dpl-name": "sfc-tun2"
+ "sff-dpl-name": "sw1-vxlangpe-0"
}
}
],
"sff-data-plane-locator": [
{
- "name": "sfc-tun2",
+ "name": "sw1-vxlangpe-0",
"data-plane-locator": {
"transport": "service-locator:vxlan-gpe",
"port": 6633,
"name": "dpi-74",
"sff-sf-data-plane-locator": {
"sf-dpl-name": "3",
- "sff-dpl-name": "sfc-tun4"
+ "sff-dpl-name": "sw2-vxlangpe-0"
}
}
],
"sff-data-plane-locator": [
{
- "name": "sfc-tun4",
+ "name": "sw2-vxlangpe-0",
"data-plane-locator": {
"transport": "service-locator:vxlan-gpe",
"port": 6633,
],
"action-ref": [
{
- "name": "allow1",
+ "name": "chain1",
"order": 0
}
]
+++ /dev/null
-Uninitialised. Please do a ./cleandemo.sh
if __name__ == "__main__" :
flows=call_dpctl().split("recirc_id")
+ print
+ print "Flows from dpctl:"
+ print
for flow in flows:
- print flow
+ if flow != "": print "recirc_id"+flow
ovs-ofctl dump-groups $sw -OOpenFlow13
if [ "$TABLE" ]
then
- ovs-ofctl dump-flows $sw -OOpenFlow13 table=$TABLE
+ ovs-ofctl dump-flows $sw -OOpenFlow13 table=$TABLE --rsort=priority
else
ovs-ofctl dump-flows $sw -OOpenFlow13
fi
-ovs-appctl ofproto/trace $1
+STR=$1
+
+TRACE=${STR%", packets"*}
+
+ovs-appctl ofproto/trace $TRACE
<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.5.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.5.2</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.SourceMapper;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchListener;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcIidFactory;
import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
import org.opendaylight.groupbasedpolicy.util.IidFactory;
import org.opendaylight.groupbasedpolicy.util.SingletonTask;
+import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.of.renderer.rev151123.SfcOfRendererConfig;
+import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.of.renderer.rev151123.SfcOfRendererConfigBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig.LearningMode;
* registry
*/
public class PolicyManager
- implements SwitchListener, EndpointListener, DataTreeChangeListener<ResolvedPolicy>, Closeable {
- private static final Logger LOG =
- LoggerFactory.getLogger(PolicyManager.class);
+ implements SwitchListener, EndpointListener, DataTreeChangeListener<ResolvedPolicy>, Closeable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PolicyManager.class);
private Map<InstanceIdentifier<Table>, TableBuilder> previousGbpFlows = new HashMap<>();
private short tableOffset;
private static final short TABLEID_PORTSECURITY = 0;
- private static final short TABLEID_INGRESS_NAT = 1;
+ private static final short TABLEID_INGRESS_NAT = 1;
private static final short TABLEID_SOURCE_MAPPER = 2;
private static final short TABLEID_DESTINATION_MAPPER = 3;
private static final short TABLEID_POLICY_ENFORCER = 4;
private static final short TABLEID_EGRESS_NAT = 5;
private static final short TABLEID_EXTERNAL_MAPPER = 6;
+ private static final short TABLEID_SFC_INGRESS = 7;
+ private static final short TABLEID_SFC_EGRESS = 0;
private final SwitchManager switchManager;
private final EndpointManager endpointManager;
*/
private final static int FLOW_UPDATE_DELAY = 250;
- public PolicyManager(DataBroker dataBroker,
- SwitchManager switchManager,
- EndpointManager endpointManager,
- ScheduledExecutorService executor,
- short tableOffset) {
+ public PolicyManager(DataBroker dataBroker, SwitchManager switchManager, EndpointManager endpointManager,
+ ScheduledExecutorService executor, short tableOffset) {
super();
this.switchManager = switchManager;
this.executor = executor;
this.endpointManager = endpointManager;
endpointManager.registerListener(this);
+ if (!setSfcTableOffset(TABLEID_SFC_INGRESS, TABLEID_SFC_EGRESS)) {
+ LOG.error("Could not set SFC Ingress Table offset.");
+ }
flowUpdateTask = new SingletonTask(executor, new FlowUpdateTask());
scheduleUpdate();
LOG.debug("Initialized OFOverlay policy manager");
}
+ private boolean setSfcTableOffset(short tableidSfcIngress, short tableidSfcEgress) {
+ SfcOfRendererConfig sfcOfRendererConfig = new SfcOfRendererConfigBuilder()
+ .setSfcOfTableOffset(tableidSfcIngress).setSfcOfAppEgressTableOffset(tableidSfcEgress).build();
+ WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
+ wTx.put(LogicalDatastoreType.CONFIGURATION, SfcIidFactory.sfcOfRendererConfigIid(), sfcOfRendererConfig);
+ return DataStoreHelper.submitToDs(wTx);
+ }
+
private List<? extends OfTable> createFlowPipeline(OfContext ofCtx) {
// TODO - PORTSECURITY is kept in table 0.
// According to openflow spec,processing on vSwitch always starts from table 0.
// Packets will be droped if table 0 is empty.
// Alternative workaround - table-miss flow entries in table 0.
- return ImmutableList.of(new PortSecurity(ofCtx, (short) 0),
- new GroupTable(ofCtx),
- new IngressNatMapper(ofCtx, getTABLEID_INGRESS_NAT()),
- new SourceMapper(ofCtx, getTABLEID_SOURCE_MAPPER()),
- new DestinationMapper(ofCtx, getTABLEID_DESTINATION_MAPPER()),
- new PolicyEnforcer(ofCtx, getTABLEID_POLICY_ENFORCER()),
- new EgressNatMapper(ofCtx, getTABLEID_EGRESS_NAT()),
- new ExternalMapper(ofCtx, getTABLEID_EXTERNAL_MAPPER())
- );
+ return ImmutableList.of(new PortSecurity(ofCtx, (short) 0), new GroupTable(ofCtx),
+ new IngressNatMapper(ofCtx, getTABLEID_INGRESS_NAT()),
+ new SourceMapper(ofCtx, getTABLEID_SOURCE_MAPPER()),
+ new DestinationMapper(ofCtx, getTABLEID_DESTINATION_MAPPER()),
+ new PolicyEnforcer(ofCtx, getTABLEID_POLICY_ENFORCER()),
+ new EgressNatMapper(ofCtx, getTABLEID_EGRESS_NAT()),
+ new ExternalMapper(ofCtx, getTABLEID_EXTERNAL_MAPPER()));
}
/**
}
/**
- * @param tableIDs - IDs of tables to delete
+ * @param tableIDs - IDs of tables to delete
* @return ListenableFuture<Void> - which will be filled when clearing is done
*/
private ListenableFuture<Void> removeUnusedTables(final List<Short> tableIDs) {
return tableIds;
}
- private ListenableFuture<Void> deleteTableIfExists(final ReadWriteTransaction rwTx, final InstanceIdentifier<Table> tablePath){
- return Futures.transform(rwTx.read(LogicalDatastoreType.CONFIGURATION, tablePath), new Function<Optional<Table>, Void>() {
-
- @Override
- public Void apply(Optional<Table> optTable) {
- if(optTable.isPresent()){
- rwTx.delete(LogicalDatastoreType.CONFIGURATION, tablePath);
- }
- return null;
- }});
+ private ListenableFuture<Void> deleteTableIfExists(final ReadWriteTransaction rwTx,
+ final InstanceIdentifier<Table> tablePath) {
+ return Futures.transform(rwTx.read(LogicalDatastoreType.CONFIGURATION, tablePath),
+ new Function<Optional<Table>, Void>() {
+
+ @Override
+ public Void apply(Optional<Table> optTable) {
+ if (optTable.isPresent()) {
+ rwTx.delete(LogicalDatastoreType.CONFIGURATION, tablePath);
+ }
+ return null;
+ }
+ });
}
// **************
// **************
public short getTABLEID_PORTSECURITY() {
- return (short)(tableOffset+TABLEID_PORTSECURITY);
+ return (short) (tableOffset + TABLEID_PORTSECURITY);
}
-
public short getTABLEID_INGRESS_NAT() {
- return (short)(tableOffset+TABLEID_INGRESS_NAT);
+ return (short) (tableOffset + TABLEID_INGRESS_NAT);
}
-
public short getTABLEID_SOURCE_MAPPER() {
- return (short)(tableOffset+TABLEID_SOURCE_MAPPER);
+ return (short) (tableOffset + TABLEID_SOURCE_MAPPER);
}
-
public short getTABLEID_DESTINATION_MAPPER() {
- return (short)(tableOffset+TABLEID_DESTINATION_MAPPER);
+ return (short) (tableOffset + TABLEID_DESTINATION_MAPPER);
}
-
public short getTABLEID_POLICY_ENFORCER() {
- return (short)(tableOffset+TABLEID_POLICY_ENFORCER);
+ return (short) (tableOffset + TABLEID_POLICY_ENFORCER);
}
-
public short getTABLEID_EGRESS_NAT() {
- return (short)(tableOffset+TABLEID_EGRESS_NAT);
+ return (short) (tableOffset + TABLEID_EGRESS_NAT);
}
-
public short getTABLEID_EXTERNAL_MAPPER() {
- return (short)(tableOffset+TABLEID_EXTERNAL_MAPPER);
+ return (short) (tableOffset + TABLEID_EXTERNAL_MAPPER);
}
+ public short getTABLEID_SFC_EGRESS() {
+ return TABLEID_SFC_EGRESS;
+ }
+
+ public short getTABLEID_SFC_INGRESS() {
+ return TABLEID_SFC_INGRESS;
+ }
public TableId verifyMaxTableId(short tableOffset) {
- return new TableId((short)(tableOffset+TABLEID_EXTERNAL_MAPPER));
+ return new TableId((short) (tableOffset + TABLEID_EXTERNAL_MAPPER));
}
@Override
}
@Override
- public void nodeEndpointUpdated(NodeId nodeId, EpKey epKey){
+ public void nodeEndpointUpdated(NodeId nodeId, EpKey epKey) {
scheduleUpdate();
}
/**
* Set the learning mode to the specified value
+ *
* @param learningMode the learning mode to set
*/
public void setLearningMode(LearningMode learningMode) {
* Update the flows on a particular switch
*/
private class SwitchFlowUpdateTask implements Callable<Void> {
+
private final OfWriter ofWriter;
public SwitchFlowUpdateTask(OfWriter ofWriter) {
try {
table.sync(node, ofWriter);
} catch (Exception e) {
- LOG.error("Failed to write Openflow table {}",
- table.getClass().getSimpleName(), e);
+ LOG.error("Failed to write Openflow table {}", table.getClass().getSimpleName(), e);
}
}
}
}
/**
- * Update all flows on all switches as needed. Note that this will block
+ * Update all flows on all switches as needed. Note that this will block
* one of the threads on the executor.
*/
private class FlowUpdateTask implements Runnable {
+
@Override
public void run() {
LOG.debug("Beginning flow update task");
- CompletionService<Void> ecs
- = new ExecutorCompletionService<>(executor);
+ CompletionService<Void> ecs = new ExecutorCompletionService<>(executor);
OfWriter ofWriter = new OfWriter();
import java.math.BigInteger;
+import org.apache.commons.lang3.StringUtils;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PolicyEnforcer.NetworkElements;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.ChainAction;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.annotations.VisibleForTesting;
+
public class ChainActionFlows {
private static final Logger LOG = LoggerFactory.getLogger(ChainAction.class);
NodeConnectorId localNodeTunPort = ctx.getSwitchManager().getTunnelPort(localNodeId, TunnelTypeVxlanGpe.class);
NodeConnectorId destNodeTunPort = ctx.getSwitchManager().getTunnelPort(destNodeId, TunnelTypeVxlanGpe.class);
+ Ipv4Address tunDestAddress = ctx.getSwitchManager()
+ .getTunnelIP(netElements.getDstNodeId(), TunnelTypeVxlanGpe.class)
+ .getIpv4Address();
if (localNodeTunPort == null || destNodeTunPort == null) {
LOG.error("createChainTunnelFlows: No valid VXLAN GPE tunnel for Node {} or Node {}", localNodeId,
destNodeId);
return;
}
- ofWriter.writeFlow(localNodeId, ctx.getPolicyManager().getTABLEID_PORTSECURITY(),
- allowFromChainPort(localNodeTunPort, ctx.getPolicyManager().getTABLEID_PORTSECURITY(), ctx));
+ ofWriter.writeFlow(localNodeId, ctx.getPolicyManager().getTABLEID_PORTSECURITY(), allowFromChainPort(
+ sfcNshHeader, localNodeTunPort, ctx.getPolicyManager().getTABLEID_PORTSECURITY(), ctx));
ofWriter.writeFlow(localNodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER(),
allowFromChainTunnel(localNodeTunPort, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER()));
- ofWriter.writeFlow(
- localNodeId,
- ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER(),
- createExternalFlow(sfcNshHeader, localNodeTunPort, netElements, ctx.getPolicyManager()
- .getTABLEID_EXTERNAL_MAPPER(), ctx));
-
- ofWriter.writeFlow(
- destNodeId,
- ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(),
- createChainTunnelFlow(sfcNshHeader, destNodeTunPort, epOrdinals, ctx.getPolicyManager()
- .getTABLEID_SOURCE_MAPPER(), ctx));
-
- ofWriter.writeFlow(
- destNodeId,
- ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(),
- createChainBroadcastFlow(sfcNshHeader, destNodeTunPort, epOrdinals, ctx.getPolicyManager()
- .getTABLEID_SOURCE_MAPPER(), ctx));
+ ofWriter.writeFlow(localNodeId, ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER(),
+ createExternalFlow(sfcNshHeader, localNodeTunPort, netElements,
+ ctx.getPolicyManager(), ctx.getSwitchManager(), tunDestAddress));
+
+ ofWriter.writeFlow(destNodeId, ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(), createChainTunnelFlow(
+ sfcNshHeader, destNodeTunPort, epOrdinals, ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(), ctx));
+
+ ofWriter.writeFlow(destNodeId, ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(), createChainBroadcastFlow(
+ sfcNshHeader, destNodeTunPort, epOrdinals, ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER(), ctx));
}
private static Flow createChainBroadcastFlow(SfcNshHeader sfcNshHeader, NodeConnectorId tunPort,
addNxNspMatch(mb, sfcNshHeader.getNshNspFromChain());
addNxTunIdMatch(mb, fdId);
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action fdReg = nxLoadRegAction(
- NxmNxReg5.class, BigInteger.valueOf(fdId));
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action fdReg =
+ nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
Match match = mb.build();
FlowId flowId = FlowIdUtils.newFlowId(tableId, "chainbroadcast", match);
FlowBuilder flowb = base(tableId).setId(flowId)
- .setPriority(Integer.valueOf(150))
+ .setPriority(150)
.setMatch(match)
- .setInstructions(
- instructions(applyActionIns(fdReg), gotoTableIns(ctx.getPolicyManager()
- .getTABLEID_DESTINATION_MAPPER())));
+ .setInstructions(instructions(applyActionIns(fdReg),
+ gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
return flowb.build();
}
- private static Flow createExternalFlow(SfcNshHeader sfcNshHeader, NodeConnectorId tunPort,
- NetworkElements netElements, short tableId, OfContext ctx) {
+ @VisibleForTesting
+ static Flow createExternalFlow(SfcNshHeader sfcNshHeader, NodeConnectorId tunPort, NetworkElements netElements,
+ PolicyManager policyManager, SwitchManager switchManager, Ipv4Address ipTunDest) {
+
+ short tableId = policyManager.getTABLEID_EXTERNAL_MAPPER();
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadC1;
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action outputAction;
Integer priority = 1000;
- int matchTunnelId=sfcNshHeader.getNshMetaC2().intValue();
- Long l3c=Long.valueOf(netElements.getSrcEpOrdinals().getL3Id());
+ int matchTunnelId = sfcNshHeader.getNshMetaC2().intValue();
+ Long l3c = (long) netElements.getSrcEpOrdinals().getL3Id();
+ loadC1 = nxLoadNshc1RegAction(sfcNshHeader.getNshMetaC1());
+
+ // Test for if SFF is on same node
+ IpAddress ipAddress = switchManager.getTunnelIP(netElements.getLocalNodeId(), TunnelTypeVxlanGpe.class);
+
+ if (ipAddress != null && ipAddress.getIpv4Address().equals(sfcNshHeader.getNshTunIpDst())) {
+ Integer newPort = returnOfPortFromNodeConnector(tunPort);
+ outputAction = FlowUtils.createActionResubmit(newPort, policyManager.getTABLEID_SFC_EGRESS());
+ } else {
+ outputAction = outputAction(tunPort);
+ }
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadC1 = nxLoadNshc1RegAction(sfcNshHeader.getNshMetaC1());
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadC2 = nxLoadNshc2RegAction(sfcNshHeader.getNshMetaC2());
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunVnid = nxLoadTunIdAction(
- BigInteger.valueOf(sfcNshHeader.getNshMetaC2()), false);
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunDest = nxLoadTunIPv4Action(
- sfcNshHeader.getNshTunIpDst().getValue(), false);
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadC2 =
+ nxLoadNshc2RegAction(sfcNshHeader.getNshMetaC2());
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunVnid =
+ nxLoadTunIdAction(BigInteger.valueOf(sfcNshHeader.getNshMetaC2()), false);
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunDest =
+ nxLoadTunIPv4Action(sfcNshHeader.getNshTunIpDst().getValue(), false);
MatchBuilder mb = new MatchBuilder();
addNxRegMatch(mb, RegMatch.of(NxmNxReg6.class, l3c));
addNxNspMatch(mb, sfcNshHeader.getNshNspToChain());
addNxNsiMatch(mb, sfcNshHeader.getNshNsiToChain());
if (!netElements.getDstNodeId().equals(netElements.getSrcNodeId())) {
- addNxTunIpv4DstMatch(mb, ctx.getSwitchManager()
- .getTunnelIP(netElements.getDstNodeId(), TunnelTypeVxlanGpe.class)
- .getIpv4Address());
+ addNxTunIpv4DstMatch(mb, ipTunDest);
priority = 1500;
}
Match match = mb.build();
FlowId flowId = FlowIdUtils.newFlowId(tableId, "chainexternal", match);
- FlowBuilder flowb = base(tableId).setId(flowId)
- .setPriority(Integer.valueOf(priority))
- .setMatch(match)
- .setInstructions(
- instructions(applyActionIns(loadC1, loadC2, loadChainTunDest, loadChainTunVnid,
- outputAction(tunPort))));
+ FlowBuilder flowb =
+ base(tableId).setId(flowId).setPriority(priority).setMatch(match).setInstructions(
+ instructions(applyActionIns(loadC1, loadC2, loadChainTunDest, loadChainTunVnid, outputAction)));
return flowb.build();
}
addNxNspMatch(mb, sfcNshHeader.getNshNspFromChain());
addNxNsiMatch(mb, sfcNshHeader.getNshNsiFromChain());
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action segReg = nxLoadRegAction(
- NxmNxReg0.class, BigInteger.valueOf(egId));
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action scgReg = nxLoadRegAction(
- NxmNxReg1.class, BigInteger.valueOf(0xffffff));
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action bdReg = nxLoadRegAction(
- NxmNxReg4.class, BigInteger.valueOf(bdId));
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action fdReg = nxLoadRegAction(
- NxmNxReg5.class, BigInteger.valueOf(fdId));
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action vrfReg = nxLoadRegAction(
- NxmNxReg6.class, BigInteger.valueOf(l3Id));
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action segReg =
+ nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(egId));
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action scgReg =
+ nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(0xffffff));
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action bdReg =
+ nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(bdId));
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action fdReg =
+ nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
+ org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action vrfReg =
+ nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(l3Id));
Match match = mb.build();
FlowId flowId = FlowIdUtils.newFlowId(tableId, "chaintunnel", match);
- FlowBuilder flowb = base(tableId).setId(flowId)
- .setPriority(Integer.valueOf(150))
- .setMatch(match)
- .setInstructions(
- instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg),
- gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
+ FlowBuilder flowb =
+ base(tableId).setId(flowId).setPriority(150).setMatch(match).setInstructions(
+ instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg),
+ gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
return flowb.build();
}
- private static Flow allowFromChainPort(NodeConnectorId port, short tableId, OfContext ctx) {
+ private static Flow allowFromChainPort(SfcNshHeader sfcNshHeader, NodeConnectorId port, short tableId,
+ OfContext ctx) {
+
+ // Matching on last NSP/NSI that SFF leaves on but with C1=0
+ MatchBuilder mb = new MatchBuilder();
+ FlowUtils.addNxNshc1RegMatch(mb, 0L);
+ FlowUtils.addNxNsiMatch(mb, sfcNshHeader.getNshNsiFromChain());
+ FlowUtils.addNxNspMatch(mb, sfcNshHeader.getNshNspFromChain());
+ Match match = mb.setInPort(port).build();
- Match match = new MatchBuilder().setInPort(port).build();
FlowId flowId = FlowIdUtils.newFlowId(tableId, "chainport", match);
- FlowBuilder flowb = base(tableId).setId(flowId)
- .setPriority(Integer.valueOf(200))
- .setMatch(match)
- .setInstructions(FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER()));
+ FlowBuilder flowb =
+ base(tableId).setId(flowId).setPriority(1200).setMatch(match).setInstructions(
+ FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER()));
return flowb.build();
}
private static Flow allowFromChainTunnel(NodeConnectorId tunPort, short tableId) {
MatchBuilder mb = new MatchBuilder().setInPort(tunPort);
- addNxRegMatch(mb, RegMatch.of(NxmNxReg1.class, Long.valueOf(0xffffff)));
+ addNxRegMatch(mb, RegMatch.of(NxmNxReg1.class, 0xffffffL));
Match match = mb.build();
FlowId flowId = FlowIdUtils.newFlowId(tableId, "chainport", match);
- FlowBuilder flow = base(tableId).setId(flowId)
- .setMatch(match)
- .setPriority(65000)
- .setInstructions(instructions(applyActionIns(nxOutputRegAction(NxmNxReg7.class))));
+ FlowBuilder flow = base(tableId).setId(flowId).setMatch(match).setPriority(65000).setInstructions(
+ instructions(applyActionIns(nxOutputRegAction(NxmNxReg7.class))));
return flow.build();
}
+ @VisibleForTesting
+ static Integer returnOfPortFromNodeConnector(NodeConnectorId nodeConnectorId) {
+ String[] elements = StringUtils.split(nodeConnectorId.getValue(), ":");
+ if (elements.length != 3)
+ return null;
+ return new Integer(elements[2]);
+ }
+
/**
* Get a base flow builder with some common features already set
*/
import java.util.ArrayList;
import java.util.List;
+import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
+import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action.ActionUtil;
+import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action.ResubmitConvertor;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionResubmitBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.resubmit.grouping.NxActionResubmitBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
/**
* ARP ethertype
*/
- public static final Long ARP = Long.valueOf(0x0806);
+ public static final Long ARP = 0x0806L;
/**
* IPv4 ethertype
*/
- public static final Long IPv4 = Long.valueOf(0x0800);
+ public static final Long IPv4 = 0x0800L;
/**
* IPv6 ethertype
*/
- public static final Long IPv6 = Long.valueOf(0x86DD);
+ public static final Long IPv6 = 0x86DDL;
/**
* VLAN ethertype
*/
- public static final Integer VLAN = Integer.valueOf(0x8100);
+ public static final Integer VLAN = 0x8100;
/**
* Creates an Instance Identifier (path) for node with specified id
* @param nodeId the ID of the node
* @return the {@link InstanceIdentifier}
*/
- public static final InstanceIdentifier<Node> createNodePath(final NodeId nodeId) {
+ public static InstanceIdentifier<Node> createNodePath(final NodeId nodeId) {
return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(nodeId)).build();
}
* @param tableId the ID of the table
* @return the {@link InstanceIdentifier}
*/
- public static final InstanceIdentifier<Table> createTablePath(final NodeId nodeId, final short tableId) {
+ public static InstanceIdentifier<Table> createTablePath(final NodeId nodeId, final short tableId) {
return createNodePath(nodeId).builder()
.augmentation(FlowCapableNode.class)
.child(Table.class, new TableKey(tableId))
* @param groupId the ID of the group table
* @return the {@link InstanceIdentifier}
*/
- public static final InstanceIdentifier<Group> createGroupPath(final NodeId nodeId, final GroupId groupId) {
+ public static InstanceIdentifier<Group> createGroupPath(final NodeId nodeId, final GroupId groupId) {
return createNodePath(nodeId).builder()
.augmentation(FlowCapableNode.class)
.child(Group.class, new GroupKey(groupId))
* @param bucketId the ID of the bucket in the group table
* @return the {@link InstanceIdentifier}
*/
- public static final InstanceIdentifier<Bucket> createBucketPath(final NodeId nodeId, final GroupId groupId,
- final BucketId bucketId) {
+ public static InstanceIdentifier<Bucket> createBucketPath(final NodeId nodeId, final GroupId groupId,
+ final BucketId bucketId) {
return createNodePath(nodeId).builder()
.augmentation(FlowCapableNode.class)
.child(Group.class, new GroupKey(groupId))
* @param flowKey the flow key
* @return the {@link InstanceIdentifier}
*/
- public static InstanceIdentifier<Flow> createFlowPath(final InstanceIdentifier<Table> table, final FlowKey flowKey) {
+ public static InstanceIdentifier<Flow> createFlowPath(final InstanceIdentifier<Table> table,
+ final FlowKey flowKey) {
return table.child(Flow.class, flowKey);
}
public static Instructions gotoTableInstructions(short tableId) {
return new InstructionsBuilder().setInstruction(
- ImmutableList.of(new InstructionBuilder().setOrder(Integer.valueOf(0))
+ ImmutableList.of(new InstructionBuilder().setOrder(0)
.setInstruction(gotoTableIns(tableId))
.build())).build();
}
public static ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList(
Action... actions) {
- ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist = new ArrayList<>();
+ ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist =
+ new ArrayList<>();
int count = 0;
for (Action action : actions) {
- alist.add(new ActionBuilder().setOrder(Integer.valueOf(count++)).setAction(action).build());
+ alist.add(new ActionBuilder().setOrder(count++).setAction(action).build());
}
return alist;
}
public static ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList(
List<ActionBuilder> actions) {
- ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist = new ArrayList<>();
+ ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> alist =
+ new ArrayList<>();
int count = 0;
for (ActionBuilder action : actions) {
- alist.add(action.setOrder(Integer.valueOf(count++)).build());
+ alist.add(action.setOrder(count++).build());
}
return alist;
}
public static Instruction applyActionIns(Action... actions) {
- return new ApplyActionsCaseBuilder().setApplyActions(
- new ApplyActionsBuilder().setAction(actionList(actions)).build()).build();
+ return new ApplyActionsCaseBuilder()
+ .setApplyActions(new ApplyActionsBuilder().setAction(actionList(actions)).build()).build();
}
public static Instruction applyActionIns(List<ActionBuilder> actions) {
- return new ApplyActionsCaseBuilder().setApplyActions(
- new ApplyActionsBuilder().setAction(actionList(actions)).build()).build();
+ return new ApplyActionsCaseBuilder()
+ .setApplyActions(new ApplyActionsBuilder().setAction(actionList(actions)).build()).build();
}
public static Instruction writeActionIns(List<ActionBuilder> actions) {
- return new WriteActionsCaseBuilder().setWriteActions(
- new WriteActionsBuilder().setAction(actionList(actions)).build()).build();
+ return new WriteActionsCaseBuilder()
+ .setWriteActions(new WriteActionsBuilder().setAction(actionList(actions)).build()).build();
}
public static Instruction writeActionIns(Action... actions) {
- return new WriteActionsCaseBuilder().setWriteActions(
- new WriteActionsBuilder().setAction(actionList(actions)).build()).build();
+ return new WriteActionsCaseBuilder()
+ .setWriteActions(new WriteActionsBuilder().setAction(actionList(actions)).build()).build();
}
public static Instructions instructions(Instruction... instructions) {
- ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> ins = new ArrayList<>();
+ ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> ins =
+ new ArrayList<>();
int order = 0;
for (Instruction i : instructions) {
ins.add(new InstructionBuilder().setOrder(order++).setInstruction(i).build());
return new DropActionCaseBuilder().setDropAction(new DropActionBuilder().build()).build();
}
+ public static Action createActionResubmit(Integer port, final short toTable) {
+ NxActionResubmitBuilder resubmit = new NxActionResubmitBuilder().setTable(toTable);
+
+ if (port != null) {
+ resubmit.setInPort(port);
+ }
+
+ ActionResubmitBuilder actionResubmitBuilder = new ActionResubmitBuilder();
+ actionResubmitBuilder.setNxActionResubmit(resubmit.build());
+
+ ResubmitConvertor convertor = new ResubmitConvertor();
+ ActionPath ap =
+ ActionPath.NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION;
+
+ return convertor.convert(ActionUtil.createAction(actionResubmitBuilder.build()), ap);
+ }
+
public static Action outputAction(NodeConnectorId id) {
- return new OutputActionCaseBuilder().setOutputAction(
- new OutputActionBuilder().setOutputNodeConnector(new Uri(id.getValue())).build()).build();
+ return new OutputActionCaseBuilder()
+ .setOutputAction(new OutputActionBuilder().setOutputNodeConnector(new Uri(id.getValue())).build()).build();
}
public static Action groupAction(Long id) {
}
public static VlanMatch vlanMatch(int vlanId, boolean vlanIdPresent) {
- return new VlanMatchBuilder().setVlanId(
- new VlanIdBuilder().setVlanId(new VlanId(vlanId)).setVlanIdPresent(vlanIdPresent).build()).build();
+ return new VlanMatchBuilder()
+ .setVlanId(new VlanIdBuilder().setVlanId(new VlanId(vlanId)).setVlanIdPresent(vlanIdPresent).build())
+ .build();
}
- public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> pushVlanActions(int vlanId) {
- List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> actions = new ArrayList<>();
+ public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> pushVlanActions(
+ int vlanId) {
+ List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> actions =
+ new ArrayList<>();
actions.add(new ActionBuilder().setAction(pushVlanAction()).setOrder(0));
actions.add(new ActionBuilder().setAction(setVlanId(vlanId)).setOrder(1));
return actions;
int order) {
List<ActionBuilder> actionBuilders = new ArrayList<>();
actionBuilders.add(new ActionBuilder().setAction(popVlanAction()).setOrder(0));
- return new InstructionBuilder().setInstruction(
- new ApplyActionsCaseBuilder().setApplyActions(
- new ApplyActionsBuilder().setAction(actionList(actionBuilders)).build()).build())
+ return new InstructionBuilder()
+ .setInstruction(new ApplyActionsCaseBuilder()
+ .setApplyActions(new ApplyActionsBuilder().setAction(actionList(actionBuilders)).build()).build())
.setOrder(order)
.build();
}
public static Action nxLoadRegAction(DstChoice dstChoice, BigInteger value, int endOffset, boolean groupBucket) {
NxRegLoad r = new NxRegLoadBuilder().setDst(
new DstBuilder().setDstChoice(dstChoice)
- .setStart(Integer.valueOf(0))
- .setEnd(Integer.valueOf(endOffset))
+ .setStart(0)
+ .setEnd(endOffset)
.build())
.setValue(value)
.build();
public static Action nxMoveRegAction(SrcChoice srcChoice, DstChoice dstChoice, int endOffset, boolean groupBucket) {
NxRegMove r = new NxRegMoveBuilder().setSrc(
new SrcBuilder().setSrcChoice(srcChoice)
- .setStart(Integer.valueOf(0))
- .setEnd(Integer.valueOf(endOffset))
+ .setStart(0)
+ .setEnd(endOffset)
.build())
.setDst(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder().setDstChoice(
dstChoice)
- .setStart(Integer.valueOf(0))
- .setEnd(Integer.valueOf(endOffset))
+ .setStart(0)
+ .setEnd(endOffset)
.build())
+ .setDst(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder()
+ .setDstChoice(dstChoice).setStart(0).setEnd(endOffset).build())
.build();
if (groupBucket) {
return new NxActionRegMoveNodesNodeGroupBucketsBucketActionsCaseBuilder().setNxRegMove(r).build();
NxOutputReg r = new NxOutputRegBuilder().setSrc(
new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.output.reg.grouping.nx.output.reg.SrcBuilder().setSrcChoice(
srcChoice)
- .setOfsNbits(Integer.valueOf(31))
+ .setOfsNbits(31)
.build())
- .setMaxLen(Integer.valueOf(0xffff))
+ .setMaxLen(0xffff)
.build();
return new NxActionOutputRegNodesNodeTableFlowApplyActionsCaseBuilder().setNxOutputReg(r).build();
}
} else {
key = NxmNxReg7Key.class;
}
- NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxReg(
- new NxmNxRegBuilder().setReg(rm.reg).setValue(rm.value).build()).build();
+ NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxReg(new NxmNxRegBuilder().setReg(rm.reg).setValue(rm.value).build()).build();
extensions.add(new ExtensionListBuilder().setExtensionKey(key)
.setExtension(new ExtensionBuilder().addAugmentation(NxAugMatchNodesNodeTableFlow.class, am).build())
.build());
}
- GeneralAugMatchNodesNodeTableFlow m = new GeneralAugMatchNodesNodeTableFlowBuilder().setExtensionList(
- extensions).build();
+ GeneralAugMatchNodesNodeTableFlow m =
+ new GeneralAugMatchNodesNodeTableFlowBuilder().setExtensionList(extensions).build();
match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
}
public static void addNxNshc1RegMatch(MatchBuilder match, Long value) {
- NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNshc1(
- new NxmNxNshc1Builder().setValue(value).build()).build();
+ NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxNshc1(new NxmNxNshc1Builder().setValue(value).build()).build();
GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNshc1Key.class, am, match);
match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
}
public static void addNxNshc2RegMatch(MatchBuilder match, Long value) {
- NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNshc2(
- new NxmNxNshc2Builder().setValue(value).build()).build();
+ NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxNshc2(new NxmNxNshc2Builder().setValue(value).build()).build();
GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNshc2Key.class, am, match);
match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
}
public static void addNxNshc3RegMatch(MatchBuilder match, Long value) {
- NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNshc3(
- new NxmNxNshc3Builder().setValue(value).build()).build();
+ NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxNshc3(new NxmNxNshc3Builder().setValue(value).build()).build();
GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNshc3Key.class, am, match);
match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
}
public static void addNxNshc4RegMatch(MatchBuilder match, Long value) {
- NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNshc4(
- new NxmNxNshc4Builder().setValue(value).build()).build();
+ NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxNshc4(new NxmNxNshc4Builder().setValue(value).build()).build();
GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNshc4Key.class, am, match);
match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
}
public static void addNxTunIdMatch(MatchBuilder match, int tunId) {
- NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxTunId(
- new NxmNxTunIdBuilder().setValue(BigInteger.valueOf(tunId)).build()).build();
+ NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxTunId(new NxmNxTunIdBuilder().setValue(BigInteger.valueOf(tunId)).build()).build();
GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxTunIdKey.class, am, match);
match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
}
public static void addNxTunIpv4DstMatch(MatchBuilder match, Ipv4Address ipv4Address) {
- NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxTunIpv4Dst(
- new NxmNxTunIpv4DstBuilder().setIpv4Address(ipv4Address).build()).build();
+ NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxTunIpv4Dst(new NxmNxTunIpv4DstBuilder().setIpv4Address(ipv4Address).build()).build();
GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxTunIpv4DstKey.class, am, match);
match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
}
public static void addNxNsiMatch(MatchBuilder match, short nsi) {
- NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNsi(
- new NxmNxNsiBuilder().setNsi(nsi).build()).build();
+ NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxNsi(new NxmNxNsiBuilder().setNsi(nsi).build()).build();
GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNsiKey.class, am, match);
match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
}
public static void addNxNspMatch(MatchBuilder match, Long nsp) {
- NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxNsp(
- new NxmNxNspBuilder().setValue(nsp).build()).build();
+ NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxNsp(new NxmNxNspBuilder().setValue(nsp).build()).build();
GeneralAugMatchNodesNodeTableFlow m = addExtensionKeyAugmentationMatcher(NxmNxNspKey.class, am, match);
match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
}
}
private static Action pushVlanAction() {
- return new PushVlanActionCaseBuilder().setPushVlanAction(
- new PushVlanActionBuilder().setEthernetType(VLAN).build()).build();
+ return new PushVlanActionCaseBuilder()
+ .setPushVlanAction(new PushVlanActionBuilder().setEthernetType(VLAN).build()).build();
}
private static Action popVlanAction() {
}
private static Action setVlanId(int vlanId) {
- return new SetVlanIdActionCaseBuilder().setSetVlanIdAction(
- new SetVlanIdActionBuilder().setVlanId(new VlanId(vlanId)).build()).build();
+ return new SetVlanIdActionCaseBuilder()
+ .setSetVlanIdAction(new SetVlanIdActionBuilder().setVlanId(new VlanId(vlanId)).build()).build();
}
private static List<ExtensionList> getExistingGeneralAugMatchNodesNodeTableFlow(MatchBuilder match) {
ArrayList<ExtensionList> extensions = new ArrayList<>();
if (match.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class) != null) {
- List<ExtensionList> existingExtensions = match.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class)
- .getExtensionList();
+ List<ExtensionList> existingExtensions =
+ match.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class).getExtensionList();
if (existingExtensions != null && !existingExtensions.isEmpty()) {
extensions.addAll(existingExtensions);
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlanGpe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public PortSecurity(OfContext ctx, short tableId) {
super(ctx);
- this.TABLE_ID=tableId;
+ TABLE_ID=tableId;
}
@Override
public void sync(NodeId nodeId, OfWriter ofWriter) {
// Allow traffic from tunnel ports
- NodeConnectorId tunnelIf = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class);
- if (tunnelIf != null)
- ofWriter.writeFlow(nodeId, TABLE_ID, allowFromPort(tunnelIf));
+ NodeConnectorId vxLanTunnel = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class);
+ NodeConnectorId vxLanGpeTunnel = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlanGpe.class);
+ if (vxLanTunnel != null)
+ ofWriter.writeFlow(nodeId, TABLE_ID, allowFromPort(vxLanTunnel));
+ if (vxLanGpeTunnel != null)
+ ofWriter.writeFlow(nodeId, TABLE_ID, allowFromPort(vxLanGpeTunnel));
// Default drop all
- ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID));
+ ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(1, null, TABLE_ID));
// Drop IP traffic that doesn't match a source IP rule
- ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(110), FlowUtils.ARP, TABLE_ID));
- ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(111), FlowUtils.IPv4, TABLE_ID));
- ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(112), FlowUtils.IPv6, TABLE_ID));
+ ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(110, FlowUtils.ARP, TABLE_ID));
+ ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(111, FlowUtils.IPv4, TABLE_ID));
+ ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(112, FlowUtils.IPv6, TABLE_ID));
Set<TenantId> tenantIds = new HashSet<>();
for (Endpoint ep : ctx.getEndpointManager().getEndpointsForNode(nodeId)) {
FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "allow", match);
FlowBuilder flowb = base()
.setId(flowid)
- .setPriority(Integer.valueOf(300))
+ .setPriority(300)
.setMatch(match)
.setInstructions(FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER()));
return flowb.build();
.setInPort(ofc.getNodeConnectorId())
.build();
FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "dhcp", match);
- Flow flow = base()
+ return base()
.setPriority(priority)
.setId(flowid)
.setMatch(match)
.setInstructions(FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_SOURCE_MAPPER()))
.build();
- return flow;
}
private void l3flow(OfWriter ofWriter, NodeId nodeId,
for (L3Address l3 : ep.getL3Address()) {
if (l3.getIpAddress() == null)
continue;
- Layer3Match m = null;
- Long etherType = null;
- String ikey = null;
+ Layer3Match m;
+ Long etherType;
+ String ikey;
if (l3.getIpAddress().getIpv4Address() != null) {
ikey = l3.getIpAddress().getIpv4Address().getValue() + "/32";
if (arp) {
Match match = new MatchBuilder().setInPort(nc).build();
FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "allowExternal", match);
FlowBuilder flowb = base().setId(flowid)
- .setPriority(Integer.valueOf(priority))
+ .setPriority(priority)
.setMatch(match)
.setInstructions(FlowUtils.gotoTableInstructions(ctx.getPolicyManager().getTABLEID_INGRESS_NAT()));
return flowb.build();
*/
private List<Flow> popVlanTagsOnExternalPort(NodeConnectorId nc, TenantId tenantId, Integer priority) {
List<Flow> flows = new ArrayList<>();
- for(L2FloodDomain l2Fd : ctx.getTenant(tenantId).getTenant().getForwardingContext().getL2FloodDomain()) {
- Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class);
- if (segmentation != null) {
- Integer vlanId = segmentation.getSegmentationId();
- flows.add(buildPopVlanFlow(nc, vlanId, priority));
+ if(ctx.getTenant(tenantId) != null) {
+ for (L2FloodDomain l2Fd : ctx.getTenant(tenantId).getTenant().getForwardingContext().getL2FloodDomain()) {
+ Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class);
+ if (segmentation != null) {
+ Integer vlanId = segmentation.getSegmentationId();
+ flows.add(buildPopVlanFlow(nc, vlanId, priority));
+ }
}
}
return flows;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.ServiceFunctionPaths;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPathKey;
+import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.of.renderer.rev151123.SfcOfRendererConfig;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class SfcIidFactory {
public static InstanceIdentifier<ServiceFunctionChain> sfcIid(SfcName sfcName) {
- ServiceFunctionChainKey serviceFunctionChainKey =
- new ServiceFunctionChainKey(sfcName);
+ ServiceFunctionChainKey serviceFunctionChainKey = new ServiceFunctionChainKey(sfcName);
return InstanceIdentifier.builder(ServiceFunctionChains.class)
- .child(ServiceFunctionChain.class, serviceFunctionChainKey).build();
+ .child(ServiceFunctionChain.class, serviceFunctionChainKey)
+ .build();
}
public static InstanceIdentifier<ServiceFunctionPath> sfpIid(SfpName sfpName) {
ServiceFunctionPathKey serviceFunctionPathKey = new ServiceFunctionPathKey(sfpName);
return InstanceIdentifier.builder(ServiceFunctionPaths.class)
- .child(ServiceFunctionPath.class, serviceFunctionPathKey).build();
+ .child(ServiceFunctionPath.class, serviceFunctionPathKey)
+ .build();
}
public static InstanceIdentifier<RenderedServicePath> rspIid(RspName rspName) {
RenderedServicePathKey rspKey = new RenderedServicePathKey(rspName);
- return InstanceIdentifier.builder(RenderedServicePaths.class)
- .child(RenderedServicePath.class, rspKey).build();
+ return InstanceIdentifier.builder(RenderedServicePaths.class).child(RenderedServicePath.class, rspKey).build();
+ }
+
+ public static InstanceIdentifier<SfcOfRendererConfig> sfcOfRendererConfigIid() {
+ return InstanceIdentifier.builder(SfcOfRendererConfig.class).build();
+
}
}
}
}
+ /*
+ * TODO: should add "portname" to this instead of using heuristic name.
+ * Then SwitchManager could pull from here potentially. The only things that should
+ * populate this are REST or OVSDB-Neutron ... but now we could listen on OVSDB for when
+ * an SFF creates this for us and use the same tunnel...
+ */
augment "/inv:nodes/inv:node" {
ext:augment-identifier "of-overlay-node-config";
list tunnel {
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.groupbasedpolicy.dto.EpKey;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DataStoreHelper.class})
public class PolicyManagerTest {
// constant values used by the tested class implementation
private Flow flow;
@Before
- public void setUp() {
+ public void setUp() throws Exception {
EndpointManager endpointManager = mock(EndpointManager.class);
ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
dataBroker = mock(DataBroker.class);
readWriteTransaction = mock(ReadWriteTransaction.class);
when(dataBroker.newReadWriteTransaction()).thenReturn(readWriteTransaction);
+ PowerMockito.stub(PowerMockito.method(DataStoreHelper.class, "submitToDs")).toReturn(true);
manager = new PolicyManager(dataBroker, switchManager,
endpointManager, executor, tableOffset);
+ ///manager = mock(PolicyManager.class);
+
nodeId = mock(NodeId.class);
tableId = 5;
flow = mock(Flow.class);
--- /dev/null
+/*\r
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.when;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PolicyEnforcer.NetworkElements;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader.SfcNshHeaderBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
+\r
+public class ChainActionFlowsTest {\r
+\r
+ private SfcNshHeader sfcNshHeader;\r
+ private NodeConnectorId tunPort;\r
+ private NetworkElements netElements;\r
+ private PolicyManager policyManager;\r
+ private SwitchManager switchManager;\r
+ private Ipv4Address ip1 = new Ipv4Address("10.1.1.1");\r
+ private Ipv4Address ip2 = new Ipv4Address("10.1.1.2");\r
+\r
+ @Before\r
+ public void setup() {\r
+ policyManager = mock(PolicyManager.class);\r
+ switchManager = mock(SwitchManager.class);\r
+ EndpointFwdCtxOrdinals ords = mock(EndpointFwdCtxOrdinals.class);\r
+ sfcNshHeader = mock(SfcNshHeader.class);\r
+ netElements = mock(NetworkElements.class);\r
+ when(netElements.getSrcNodeId()).thenReturn(new NodeId("openflow:1"));\r
+ when(netElements.getSrcEpOrdinals()).thenReturn(ords);\r
+ when(netElements.getSrcEpOrdinals().getL3Id()).thenReturn(7);\r
+ when(netElements.getDstNodeId()).thenReturn(new NodeId("openflow:1"));\r
+ when(netElements.getDstEpOrdinals()).thenReturn(ords);\r
+ when(netElements.getDstEpOrdinals().getL3Id()).thenReturn(7);\r
+ when(netElements.getLocalNodeId()).thenReturn(new NodeId("openflow:1"));\r
+ tunPort = new NodeConnectorId("openflow:1:42");\r
+ }\r
+\r
+ @Test\r
+ public void createExternalFlowTest() throws Exception {\r
+ // Note C1 != tunDest ie ip1 and ip2 - output action\r
+ sfcNshHeader = new SfcNshHeaderBuilder().setNshMetaC1(SfcNshHeader.convertIpAddressToLong(ip1))\r
+ .setNshTunIpDst(ip2)\r
+ .setNshMetaC2(7L)\r
+ .setNshNsiToChain((short) 1)\r
+ .build();\r
+\r
+ Flow flow = ChainActionFlows.createExternalFlow(sfcNshHeader, tunPort, netElements, policyManager, switchManager, ip2);\r
+ assertEquals(policyManager.getTABLEID_EXTERNAL_MAPPER(), flow.getTableId().shortValue());\r
+ assertTrue(flow.getInstructions().getInstruction()\r
+ .get(0).getInstruction().toString().contains("_outputAction=OutputAction"));\r
+\r
+ // Note C1 == tunDest ie ip1\r
+ sfcNshHeader = new SfcNshHeaderBuilder().setNshMetaC1(SfcNshHeader.convertIpAddressToLong(ip1))\r
+ .setNshTunIpDst(ip1)\r
+ .setNshMetaC2(7L)\r
+ .setNshNsiToChain((short) 1)\r
+ .build();\r
+\r
+ flow = ChainActionFlows.createExternalFlow(sfcNshHeader, tunPort, netElements, policyManager, switchManager, ip2);\r
+\r
+ assertTrue(flow.getInstructions().getInstruction()\r
+ .get(0).getInstruction().toString().contains("_outputAction=OutputAction"));\r
+ }\r
+\r
+ @Test\r
+ public void returnOfPortFromNodeConnectorTest() {\r
+ NodeConnectorId ncId = new NodeConnectorId("openflow:1:42");\r
+ Integer port = ChainActionFlows.returnOfPortFromNodeConnector(ncId);\r
+ assertEquals(new Integer("42"), port);\r
+\r
+ ncId = new NodeConnectorId("openflow:1");\r
+ Assert.assertNull(ChainActionFlows.returnOfPortFromNodeConnector(ncId));\r
+ }\r
+}\r
\r
import org.junit.Before;\r
import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayNodeConfigBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.nodes.node.TunnelBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.Contract;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg7;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
import com.google.common.collect.ImmutableList;\r
\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({PolicyManager.class})\r
public class DestinationMapperTest extends FlowTableTest {\r
protected static final Logger LOG =\r
LoggerFactory.getLogger(DestinationMapperTest.class);\r
@Override\r
@Before\r
public void setup() throws Exception {\r
+ PowerMockito.stub(PowerMockito.method(PolicyManager.class, "setSfcTableOffset")).toReturn(true);\r
+\r
initCtx();\r
table = new DestinationMapper(ctx,ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER());\r
super.setup();\r
f.getMatch().getEthernetMatch())) {\r
// router ARP reply\r
Instruction ins = f.getInstructions().getInstruction().get(0);\r
- ins = f.getInstructions().getInstruction().get(0);\r
assertTrue(ins.getInstruction() instanceof ApplyActionsCase);\r
List<Action> actions = ((ApplyActionsCase) ins.getInstruction()).getApplyActions().getAction();\r
assertEquals(nxMoveEthSrcToEthDstAction(),\r
.getAddress())) {\r
// broadcast/multicast flow should output to group table\r
Instruction ins = f.getInstructions().getInstruction().get(0);\r
- ins = f.getInstructions().getInstruction().get(0);\r
assertTrue(ins.getInstruction() instanceof ApplyActionsCase);\r
List<Action> actions = ((ApplyActionsCase) ins.getInstruction()).getApplyActions().getAction();\r
assertEquals(nxMoveRegTunIdAction(NxmNxReg0.class, false),\r
actions.get(0).getAction());\r
assertEquals(Integer.valueOf(0), actions.get(0).getOrder());\r
\r
- Long v = Long.valueOf(OrdinalFactory.getContextOrdinal(tid, fd));\r
+ Long v = (long) OrdinalFactory.getContextOrdinal(tid, fd);\r
assertEquals(groupAction(v), actions.get(1).getAction());\r
assertEquals(Integer.valueOf(1), actions.get(1).getOrder());\r
count += 1;\r
\r
\r
ctx.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy()).setContract(\r
- ImmutableList.<Contract> of(baseContract(null).build())).build()).build());\r
+ ImmutableList.of(baseContract(null).build())).build()).build());\r
verifyDMap(remoteEp, localEp);\r
}\r
\r
endpointManager.addEndpoint(remoteEp);\r
\r
ctx.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy()).setContract(\r
- ImmutableList.<Contract> of(baseContract(null).build())).build()).build());\r
+ ImmutableList.of(baseContract(null).build())).build()).build());\r
verifyDMap(remoteEp, localEp);\r
}\r
\r
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import com.google.common.collect.ImmutableSet;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({PolicyManager.class})
public class ExternalMapperTest extends FlowTableTest {
private ExternalMapper mapper;
@Before
public void initialisation() {
+ PowerMockito.stub(PowerMockito.method(PolicyManager.class, "setSfcTableOffset")).toReturn(true);
+
initCtx();
tableId = 6;
nodeId = mock(NodeId.class);
.build())
.build();
endpointManager.addEndpoint(l2Ep);
- switchManager.addSwitch(nodeId,null,ImmutableSet.<NodeConnectorId>of(new NodeConnectorId("openflow:1:1")), null);
+ switchManager.addSwitch(nodeId,null,ImmutableSet.of(new NodeConnectorId("openflow:1:1")), null);
mapper.sync(nodeId, ofWriter);
verify(ofWriter, times(4)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.instructions;
import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxOutputRegAction;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.opendaylight.groupbasedpolicy.dto.ConditionGroup;
import org.opendaylight.groupbasedpolicy.dto.EgKey;
import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PolicyEnforcer.PolicyPair;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.conditions.ConditionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.Contract;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.ContractBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.ClauseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Subject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg0Key;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg2Key;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({PolicyManager.class})
public class PolicyEnforcerTest extends FlowTableTest {
- protected static final Logger LOG = LoggerFactory.getLogger(PolicyEnforcerTest.class);
-
@Override
@Before
public void setup() throws Exception {
+ PowerMockito.stub(PowerMockito.method(PolicyManager.class, "setSfcTableOffset")).toReturn(true);
+
initCtx();
table = new PolicyEnforcer(ctx, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER());
super.setup();
Endpoint ep2 = localEP().setMacAddress(new MacAddress("00:00:00:00:00:02")).build();
endpointManager.addEndpoint(ep2);
ctx.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy())
- .setContract(ImmutableList.<Contract>of(baseContract(null).build())).build()).build());
+ .setContract(ImmutableList.of(baseContract(null).build())).build()).build());
OfWriter fm = dosync(null);
assertNotEquals(0, fm.getTableForNode(nodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER())
@Test
public void testDifferentEg() throws Exception {
- assertEquals(7, doTestDifferentEg(ImmutableList.<Subject>of(baseSubject(null).build())));
- assertEquals(7, doTestDifferentEg(ImmutableList.<Subject>of(baseSubject(Direction.Bidirectional).build())));
- assertEquals(5, doTestDifferentEg(ImmutableList.<Subject>of(baseSubject(Direction.In).build())));
- assertEquals(5, doTestDifferentEg(ImmutableList.<Subject>of(baseSubject(Direction.Out).build())));
+ assertEquals(7, doTestDifferentEg(ImmutableList.of(baseSubject(null).build())));
+ assertEquals(7, doTestDifferentEg(ImmutableList.of(baseSubject(Direction.Bidirectional).build())));
+ assertEquals(5, doTestDifferentEg(ImmutableList.of(baseSubject(Direction.In).build())));
+ assertEquals(5, doTestDifferentEg(ImmutableList.of(baseSubject(Direction.Out).build())));
}
@Test
Rule rule1 = new RuleBuilder().setActionRef(
ImmutableList.of(new ActionRefBuilder().setName(new ActionName("allow")).build()))
.setClassifierRef(
- createClassifierRefs(ImmutableMap.<String, Direction>of("tcp_dst_80", Direction.In, "tcp_src_80",
+ createClassifierRefs(ImmutableMap.of("tcp_dst_80", Direction.In, "tcp_src_80",
Direction.In)))
.build();
Rule rule2 = new RuleBuilder().setActionRef(
ImmutableList.of(new ActionRefBuilder().setName(new ActionName("allow")).build()))
.setClassifierRef(
- createClassifierRefs(ImmutableMap.<String, Direction>of("tcp_dst_80", Direction.In, "tcp_src_80",
+ createClassifierRefs(ImmutableMap.of("tcp_dst_80", Direction.In, "tcp_src_80",
Direction.Out)))
.build();
Rule rule3 = new RuleBuilder().setActionRef(
ImmutableList.of(new ActionRefBuilder().setName(new ActionName("allow")).build()))
.setClassifierRef(
- createClassifierRefs(ImmutableMap.<String, Direction>of("tcp_dst_80", Direction.In, "tcp_src_80",
+ createClassifierRefs(ImmutableMap.of("tcp_dst_80", Direction.In, "tcp_src_80",
Direction.Out, "ether_type", Direction.In)))
.build();
Rule rule4 = new RuleBuilder().setActionRef(
ImmutableList.of(new ActionRefBuilder().setName(new ActionName("allow")).build()))
.setClassifierRef(
- createClassifierRefs(ImmutableMap.<String, Direction>of("tcp_dst_80", Direction.In, "tcp_dst_90",
+ createClassifierRefs(ImmutableMap.of("tcp_dst_80", Direction.In, "tcp_dst_90",
Direction.In)))
.build();
assertEquals(5,
- doTestDifferentEg(ImmutableList.<Subject>of(createSubject("s1", ImmutableList.<Rule>of(rule1)))));
+ doTestDifferentEg(ImmutableList.of(createSubject("s1", ImmutableList.of(rule1)))));
assertEquals(11,
- doTestDifferentEg(ImmutableList.<Subject>of(createSubject("s2", ImmutableList.<Rule>of(rule2)))));
+ doTestDifferentEg(ImmutableList.of(createSubject("s2", ImmutableList.of(rule2)))));
assertEquals(9,
- doTestDifferentEg(ImmutableList.<Subject>of(createSubject("s3", ImmutableList.<Rule>of(rule3)))));
+ doTestDifferentEg(ImmutableList.of(createSubject("s3", ImmutableList.of(rule3)))));
assertEquals(3,
- doTestDifferentEg(ImmutableList.<Subject>of(createSubject("s4", ImmutableList.<Rule>of(rule4)))));
+ doTestDifferentEg(ImmutableList.of(createSubject("s4", ImmutableList.of(rule4)))));
}
private int doTestDifferentEg(List<Subject> subjects) throws Exception {
Endpoint ep2 = localEP().setMacAddress(new MacAddress("00:00:00:00:00:02")).setEndpointGroup(eg2).build();
endpointManager.addEndpoint(ep2);
ctx.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy())
- .setContract(ImmutableList.<Contract>of(baseContract(subjects).build())).build()).build());
+ .setContract(ImmutableList.of(baseContract(subjects).build())).build()).build());
OfWriter fm = dosync(null);
assertNotEquals(0, fm.getTableForNode(nodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER())
.getFlow()
.size());
int count = 0;
- HashMap<String, Flow> flowMap = new HashMap<>();
for (Flow f : fm.getTableForNode(nodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER()).getFlow()) {
- flowMap.put(f.getId().getValue(), f);
if (isAllowSameEpg(f)) {
count += 1;
} else if (f.getMatch() != null && Objects.equals(tunnelId, f.getMatch().getInPort())) {
.getType()
.getValue())
&& f.getMatch().getIpMatch() != null
- && Objects.equals(Short.valueOf((short) 6), f.getMatch().getIpMatch().getIpProtocol())
+ && Objects.equals((short) 6, f.getMatch().getIpMatch().getIpProtocol())
&& f.getMatch().getLayer4Match() != null
- && (Objects.equals(new PortNumber(Integer.valueOf(80)),
+ && (Objects.equals(new PortNumber(80),
((TcpMatch) f.getMatch().getLayer4Match()).getTcpSourcePort()) || Objects.equals(
- new PortNumber(Integer.valueOf(80)),
+ new PortNumber(80),
((TcpMatch) f.getMatch().getLayer4Match()).getTcpDestinationPort()))) {
count += 1;
} else if (f.getMatch() != null
.getType()
.getValue())
&& f.getMatch().getIpMatch() != null
- && Objects.equals(Short.valueOf((short) 6), f.getMatch().getIpMatch().getIpProtocol())
+ && Objects.equals((short) 6, f.getMatch().getIpMatch().getIpProtocol())
&& f.getMatch().getLayer4Match() != null
- && (Objects.equals(new PortNumber(Integer.valueOf(80)),
+ && (Objects.equals(new PortNumber(80),
((TcpMatch) f.getMatch().getLayer4Match()).getTcpSourcePort()) || Objects.equals(
- new PortNumber(Integer.valueOf(80)),
+ new PortNumber(80),
((TcpMatch) f.getMatch().getLayer4Match()).getTcpDestinationPort()))) {
count += 1;
}
assertNotEquals(cg1Id, cg2Id);
MatchBuilder mb = new MatchBuilder();
- FlowUtils.addNxRegMatch(mb, RegMatch.of(NxmNxReg0.class, Long.valueOf(eg1Id)),
- RegMatch.of(NxmNxReg1.class, Long.valueOf(cg1Id)), RegMatch.of(NxmNxReg2.class, Long.valueOf(eg2Id)),
- RegMatch.of(NxmNxReg3.class, Long.valueOf(cg2Id)));
+ FlowUtils.addNxRegMatch(mb, RegMatch.of(NxmNxReg0.class, (long) eg1Id),
+ RegMatch.of(NxmNxReg1.class, (long) cg1Id), RegMatch.of(NxmNxReg2.class, (long) eg2Id),
+ RegMatch.of(NxmNxReg3.class, (long) cg2Id));
int count = 0;
OfWriter fm = dosync(null);
assertEquals(7, fm.getTableForNode(nodeId, ctx.getPolicyManager().getTABLEID_POLICY_ENFORCER())
providerCondGrpId = 8;
consumerEicIp = mock(IpPrefix.class);
providerEicIp = mock(IpPrefix.class);
- consumerEicIpPrefixes = new HashSet<IpPrefix>(Arrays.asList(consumerEicIp));
- providerEicIpPrefixes = new HashSet<IpPrefix>(Arrays.asList(providerEicIp));
+ consumerEicIpPrefixes = new HashSet<>(Collections.singletonList(consumerEicIp));
+ providerEicIpPrefixes = new HashSet<>(Collections.singletonList(providerEicIp));
consumerEpNodeId = mock(NodeId.class);
when(consumerEpNodeId.getValue()).thenReturn("consumerValue");
providerEpNodeId = mock(NodeId.class);
policyPair = new PolicyPair(consumerEpgId, providerEpgId, consumerCondGrpId, providerCondGrpId,
consumerEicIpPrefixes, providerEicIpPrefixes, consumerEpNodeId, providerEpNodeId);
- Assert.assertTrue(policyPair.equals(policyPair));
- Assert.assertFalse(policyPair.equals(null));
+
+ Assert.assertNotNull(policyPair);
Assert.assertFalse(policyPair.equals(new Object()));
Assert.assertFalse(other.equals(policyPair));
\r
import org.junit.Before;\r
import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
\r
import com.google.common.collect.ImmutableList;\r
import com.google.common.collect.ImmutableSet;\r
\r
import static org.junit.Assert.*;\r
\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({PolicyManager.class})\r
public class PortSecurityTest extends FlowTableTest {\r
- protected static final Logger LOG =\r
- LoggerFactory.getLogger(PortSecurityTest.class);\r
\r
private Endpoint ep = localEP()\r
.setL3Address(ImmutableList.of(new L3AddressBuilder()\r
@Override\r
@Before\r
public void setup() throws Exception {\r
+ PowerMockito.stub(PowerMockito.method(PolicyManager.class, "setSfcTableOffset")).toReturn(true);\r
+\r
initCtx();\r
table = new PortSecurity(ctx,ctx.getPolicyManager().getTABLEID_PORTSECURITY());\r
super.setup();\r
.setNodeConnectorId(new NodeConnectorId("openflow:12:1"))\r
.build())).build());\r
ctx.addTenant(baseTenant().build());\r
- OfWriter fm = dosync(null);\r
}\r
}\r