Skip to content
Snippets Groups Projects
Commit 32228e88 authored by jkhutch3's avatar jkhutch3
Browse files

Merge remote-tracking branch 'brobertson/firewall_cookies' into firewall_cookies

parents 3a86fd4a 1c839f9f
No related branches found
No related tags found
No related merge requests found
Showing with 118 additions and 4 deletions
...@@ -76,6 +76,13 @@ public class AppCookie { ...@@ -76,6 +76,13 @@ public class AppCookie {
return U64.of(APP_ID_MASK << APP_ID_SHIFT); return U64.of(APP_ID_MASK << APP_ID_SHIFT);
} }
/**
* Returns a mask suitable for matching the User field within a cookie.
*/
static public U64 getUserFieldMask() {
return U64.of(USER_MASK);
}
/** /**
* Encapsulate an application ID and a user block of stuff into a cookie * Encapsulate an application ID and a user block of stuff into a cookie
* *
......
...@@ -37,6 +37,7 @@ import org.projectfloodlight.openflow.types.IPv4Address; ...@@ -37,6 +37,7 @@ import org.projectfloodlight.openflow.types.IPv4Address;
import org.projectfloodlight.openflow.types.IPv4AddressWithMask; import org.projectfloodlight.openflow.types.IPv4AddressWithMask;
import org.projectfloodlight.openflow.types.IpProtocol; import org.projectfloodlight.openflow.types.IpProtocol;
import org.projectfloodlight.openflow.types.MacAddress; import org.projectfloodlight.openflow.types.MacAddress;
import org.projectfloodlight.openflow.types.Masked;
import org.projectfloodlight.openflow.types.OFPort; import org.projectfloodlight.openflow.types.OFPort;
import org.projectfloodlight.openflow.types.TransportPort; import org.projectfloodlight.openflow.types.TransportPort;
import org.projectfloodlight.openflow.types.U64; import org.projectfloodlight.openflow.types.U64;
...@@ -60,6 +61,7 @@ import net.floodlightcontroller.packet.TCP; ...@@ -60,6 +61,7 @@ import net.floodlightcontroller.packet.TCP;
import net.floodlightcontroller.packet.UDP; import net.floodlightcontroller.packet.UDP;
import net.floodlightcontroller.restserver.IRestApiService; import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.routing.IRoutingDecision; import net.floodlightcontroller.routing.IRoutingDecision;
import net.floodlightcontroller.routing.IRoutingService;
import net.floodlightcontroller.routing.RoutingDecision; import net.floodlightcontroller.routing.RoutingDecision;
import net.floodlightcontroller.storage.IResultSet; import net.floodlightcontroller.storage.IResultSet;
import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.IStorageSourceService;
...@@ -85,11 +87,13 @@ IFloodlightModule { ...@@ -85,11 +87,13 @@ IFloodlightModule {
private static final U64 DENY_BCAST_COOKIE = AppCookie.makeCookie(APP_ID, 0xaaaaaaaa); private static final U64 DENY_BCAST_COOKIE = AppCookie.makeCookie(APP_ID, 0xaaaaaaaa);
private static final U64 ALLOW_BCAST_COOKIE = AppCookie.makeCookie(APP_ID, 0x55555555); private static final U64 ALLOW_BCAST_COOKIE = AppCookie.makeCookie(APP_ID, 0x55555555);
private static final U64 RULE_MISS_COOKIE = AppCookie.makeCookie(APP_ID, -1); private static final U64 RULE_MISS_COOKIE = AppCookie.makeCookie(APP_ID, -1);
private static final U64 DEFAULT_COOKIE = AppCookie.makeCookie(APP_ID, 0);
// service modules needed // service modules needed
protected IFloodlightProviderService floodlightProvider; protected IFloodlightProviderService floodlightProvider;
protected IStorageSourceService storageSource; protected IStorageSourceService storageSource;
protected IRestApiService restApi; protected IRestApiService restApi;
protected IRoutingService routingService;
protected static Logger logger; protected static Logger logger;
protected List<FirewallRule> rules; // protected by synchronized protected List<FirewallRule> rules; // protected by synchronized
...@@ -170,6 +174,7 @@ IFloodlightModule { ...@@ -170,6 +174,7 @@ IFloodlightModule {
l.add(IFloodlightProviderService.class); l.add(IFloodlightProviderService.class);
l.add(IStorageSourceService.class); l.add(IStorageSourceService.class);
l.add(IRestApiService.class); l.add(IRestApiService.class);
l.add(IRoutingService.class);
return l; return l;
} }
...@@ -288,6 +293,7 @@ IFloodlightModule { ...@@ -288,6 +293,7 @@ IFloodlightModule {
floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
storageSource = context.getServiceImpl(IStorageSourceService.class); storageSource = context.getServiceImpl(IStorageSourceService.class);
restApi = context.getServiceImpl(IRestApiService.class); restApi = context.getServiceImpl(IRestApiService.class);
routingService = context.getServiceImpl(IRoutingService.class);
rules = new ArrayList<FirewallRule>(); rules = new ArrayList<FirewallRule>();
logger = LoggerFactory.getLogger(Firewall.class); logger = LoggerFactory.getLogger(Firewall.class);
...@@ -335,8 +341,18 @@ IFloodlightModule { ...@@ -335,8 +341,18 @@ IFloodlightModule {
@Override @Override
public void enableFirewall(boolean enabled) { public void enableFirewall(boolean enabled) {
logger.info("Setting firewall to {}", enabled);
this.enabled = enabled; if(this.enabled != enabled) {
logger.info("Setting firewall to {}", enabled);
this.enabled = enabled;
List<Masked<U64>> changes = new ArrayList<Masked<U64>>();
changes.add(Masked.of(DEFAULT_COOKIE, AppCookie.getAppFieldMask()));
// Add announcement that all firewall decisions changed
routingService.handleRoutingDecisionChange(changes);
}
} }
@Override @Override
...@@ -424,6 +440,22 @@ IFloodlightModule { ...@@ -424,6 +440,22 @@ IFloodlightModule {
entry.put(COLUMN_PRIORITY, Integer.toString(rule.priority)); entry.put(COLUMN_PRIORITY, Integer.toString(rule.priority));
entry.put(COLUMN_ACTION, Integer.toString(rule.action.ordinal())); entry.put(COLUMN_ACTION, Integer.toString(rule.action.ordinal()));
storageSource.insertRow(TABLE_NAME, entry); storageSource.insertRow(TABLE_NAME, entry);
U64 singleRuleMask = AppCookie.getAppFieldMask().or(AppCookie.getUserFieldMask());
List<Masked<U64>> changes = new ArrayList<Masked<U64>>();
Iterator<FirewallRule> iter = this.rules.iterator();
while (iter.hasNext()) {
FirewallRule r = iter.next();
if (r.priority >= rule.priority) {
//
changes.add(Masked.of(AppCookie.makeCookie(APP_ID, r.ruleid), singleRuleMask));
}
}
changes.add(Masked.of(RULE_MISS_COOKIE, singleRuleMask));
routingService.handleRoutingDecisionChange(changes);
} }
@Override @Override
...@@ -439,6 +471,19 @@ IFloodlightModule { ...@@ -439,6 +471,19 @@ IFloodlightModule {
} }
// delete from database // delete from database
storageSource.deleteRow(TABLE_NAME, Integer.toString(ruleid)); storageSource.deleteRow(TABLE_NAME, Integer.toString(ruleid));
//Add announcement that the rule has been deleted
Masked<U64> delDescriptor = Masked.of(
AppCookie.makeCookie(APP_ID, ruleid),
AppCookie.getAppFieldMask().or(AppCookie.getUserFieldMask()));
List<Masked<U64>> changes = new ArrayList<Masked<U64>>();
changes.add(delDescriptor);
//Add announcement that rule is added
// should we try to delete the flow even if not found in this.rules
routingService.handleRoutingDecisionChange(changes);
} }
/** /**
......
...@@ -51,6 +51,7 @@ import net.floodlightcontroller.packet.TCP; ...@@ -51,6 +51,7 @@ import net.floodlightcontroller.packet.TCP;
import net.floodlightcontroller.packet.UDP; import net.floodlightcontroller.packet.UDP;
import net.floodlightcontroller.routing.ForwardingBase; import net.floodlightcontroller.routing.ForwardingBase;
import net.floodlightcontroller.routing.IRoutingDecision; import net.floodlightcontroller.routing.IRoutingDecision;
import net.floodlightcontroller.routing.IRoutingDecisionChangedListener;
import net.floodlightcontroller.routing.IRoutingService; import net.floodlightcontroller.routing.IRoutingService;
import net.floodlightcontroller.routing.Route; import net.floodlightcontroller.routing.Route;
import net.floodlightcontroller.topology.ITopologyService; import net.floodlightcontroller.topology.ITopologyService;
...@@ -87,7 +88,7 @@ import org.projectfloodlight.openflow.types.VlanVid; ...@@ -87,7 +88,7 @@ import org.projectfloodlight.openflow.types.VlanVid;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class Forwarding extends ForwardingBase implements IFloodlightModule, IOFSwitchListener, ILinkDiscoveryListener { public class Forwarding extends ForwardingBase implements IFloodlightModule, IOFSwitchListener, ILinkDiscoveryListener, IRoutingDecisionChangedListener {
protected static Logger log = LoggerFactory.getLogger(Forwarding.class); protected static Logger log = LoggerFactory.getLogger(Forwarding.class);
final static U64 DEFAULT_FORWARDING_COOKIE = AppCookie.makeCookie(FORWARDING_APP_ID, 0); final static U64 DEFAULT_FORWARDING_COOKIE = AppCookie.makeCookie(FORWARDING_APP_ID, 0);
...@@ -160,6 +161,13 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule, IOF ...@@ -160,6 +161,13 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule, IOF
return AppCookie.makeCookie(FORWARDING_APP_ID, user_fields); return AppCookie.makeCookie(FORWARDING_APP_ID, user_fields);
} }
/** Called when the handleDecisionChange is triggered by an event (routing decision was changed in firewall).
*
* @param eventDescriptors Collection of descriptors that should be deleted from the switch.*/
public void routingDecisionChanged(Iterable<Masked<U64>> eventDescriptors) {
deleteFlowsByDescriptor(eventDescriptors);
}
/** /**
* Converts a sequence of masked IRoutingDecision descriptors into masked Forwarding cookies. * Converts a sequence of masked IRoutingDecision descriptors into masked Forwarding cookies.
* *
...@@ -627,6 +635,7 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule, IOF ...@@ -627,6 +635,7 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule, IOF
public void startUp(FloodlightModuleContext context) { public void startUp(FloodlightModuleContext context) {
super.startUp(); super.startUp();
switchService.addOFSwitchListener(this); switchService.addOFSwitchListener(this);
routingEngineService.addRoutingDecisionChangedListener(this);
/* Register only if we want to remove stale flows */ /* Register only if we want to remove stale flows */
if (REMOVE_FLOWS_ON_LINK_OR_PORT_DOWN) { if (REMOVE_FLOWS_ON_LINK_OR_PORT_DOWN) {
...@@ -634,6 +643,10 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule, IOF ...@@ -634,6 +643,10 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule, IOF
} }
} }
@Override @Override
public void switchAdded(DatapathId switchId) { public void switchAdded(DatapathId switchId) {
} }
......
...@@ -338,7 +338,7 @@ IFloodlightModule, IInfoProvider { ...@@ -338,7 +338,7 @@ IFloodlightModule, IInfoProvider {
byte[] srcMac = ofpPort.getHwAddr().getBytes(); byte[] srcMac = ofpPort.getHwAddr().getBytes();
byte[] zeroMac = { 0, 0, 0, 0, 0, 0 }; byte[] zeroMac = { 0, 0, 0, 0, 0, 0 };
if (Arrays.equals(srcMac, zeroMac)) { if (Arrays.equals(srcMac, zeroMac)) {
log.warn("Port {}/{} has zero hareware address" log.warn("Port {}/{} has zero hardware address"
+ "overwrite with lower 6 bytes of dpid", + "overwrite with lower 6 bytes of dpid",
dpid.toString(), ofpPort.getPortNo().getPortNumber()); dpid.toString(), ofpPort.getPortNo().getPortNumber());
System.arraycopy(dpidArray, 2, srcMac, 0, 6); System.arraycopy(dpidArray, 2, srcMac, 0, 6);
......
...@@ -66,4 +66,5 @@ public interface IRoutingDecision { ...@@ -66,4 +66,5 @@ public interface IRoutingDecision {
public void setHardTimeout(short hardTimeout); public void setHardTimeout(short hardTimeout);
public U64 getDescriptor(); public U64 getDescriptor();
public void setDescriptor(U64 descriptor); public void setDescriptor(U64 descriptor);
} }
package net.floodlightcontroller.routing;
import org.projectfloodlight.openflow.types.Masked;
import org.projectfloodlight.openflow.types.U64;
public interface IRoutingDecisionChangedListener {
public void routingDecisionChanged(Iterable<Masked<U64>> event);
}
...@@ -20,6 +20,7 @@ package net.floodlightcontroller.routing; ...@@ -20,6 +20,7 @@ package net.floodlightcontroller.routing;
import java.util.ArrayList; import java.util.ArrayList;
import org.projectfloodlight.openflow.types.DatapathId; import org.projectfloodlight.openflow.types.DatapathId;
import org.projectfloodlight.openflow.types.Masked;
import org.projectfloodlight.openflow.types.OFPort; import org.projectfloodlight.openflow.types.OFPort;
import org.projectfloodlight.openflow.types.U64; import org.projectfloodlight.openflow.types.U64;
...@@ -82,5 +83,20 @@ public interface IRoutingService extends IFloodlightService { ...@@ -82,5 +83,20 @@ public interface IRoutingService extends IFloodlightService {
* or not have tunnels as part of the path. * or not have tunnels as part of the path.
*/ */
public boolean routeExists(DatapathId src, DatapathId dst, boolean tunnelEnabled); public boolean routeExists(DatapathId src, DatapathId dst, boolean tunnelEnabled);
/** Register the RDCListener
* @param listener - The module that wants to listen for events
* */
public void addRoutingDecisionChangedListener(IRoutingDecisionChangedListener listener);
/** Remove the RDCListener
* @param listener - The module that wants to stop listening for events
* */
public void removeRoutingDecisionChangedListener(IRoutingDecisionChangedListener listener);
/** Handles what the listener actually does
* @param
* */
public void handleRoutingDecisionChange(Iterable<Masked<U64>> event/* IRoutingDecisionChange event */);
} }
...@@ -136,4 +136,5 @@ public class RoutingDecision implements IRoutingDecision { ...@@ -136,4 +136,5 @@ public class RoutingDecision implements IRoutingDecision {
" wildcard " + " wildcard " +
((match == null) ? null : match.toString()); ((match == null) ? null : match.toString());
} }
} }
...@@ -59,6 +59,7 @@ import net.floodlightcontroller.packet.BSN; ...@@ -59,6 +59,7 @@ import net.floodlightcontroller.packet.BSN;
import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.packet.Ethernet;
import net.floodlightcontroller.packet.LLDP; import net.floodlightcontroller.packet.LLDP;
import net.floodlightcontroller.restserver.IRestApiService; import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.routing.IRoutingDecisionChangedListener;
import net.floodlightcontroller.routing.IRoutingService; import net.floodlightcontroller.routing.IRoutingService;
import net.floodlightcontroller.routing.Link; import net.floodlightcontroller.routing.Link;
import net.floodlightcontroller.routing.Route; import net.floodlightcontroller.routing.Route;
...@@ -73,6 +74,7 @@ import org.projectfloodlight.openflow.protocol.OFVersion; ...@@ -73,6 +74,7 @@ import org.projectfloodlight.openflow.protocol.OFVersion;
import org.projectfloodlight.openflow.protocol.action.OFAction; import org.projectfloodlight.openflow.protocol.action.OFAction;
import org.projectfloodlight.openflow.protocol.match.MatchField; import org.projectfloodlight.openflow.protocol.match.MatchField;
import org.projectfloodlight.openflow.types.DatapathId; import org.projectfloodlight.openflow.types.DatapathId;
import org.projectfloodlight.openflow.types.Masked;
import org.projectfloodlight.openflow.types.OFBufferId; import org.projectfloodlight.openflow.types.OFBufferId;
import org.projectfloodlight.openflow.types.OFPort; import org.projectfloodlight.openflow.types.OFPort;
import org.projectfloodlight.openflow.types.U64; import org.projectfloodlight.openflow.types.U64;
...@@ -176,6 +178,9 @@ public class TopologyManager implements IFloodlightModule, ITopologyService, IRo ...@@ -176,6 +178,9 @@ public class TopologyManager implements IFloodlightModule, ITopologyService, IRo
* Topology Event Updater * Topology Event Updater
*/ */
protected IEventCategory<TopologyEvent> eventCategory; protected IEventCategory<TopologyEvent> eventCategory;
/** Array list that contains all of the decisionChangedListeners */
protected ArrayList<IRoutingDecisionChangedListener> decisionChangedListeners;
/** /**
* Topology Information exposed for a Topology related event - used inside * Topology Information exposed for a Topology related event - used inside
...@@ -854,6 +859,7 @@ public class TopologyManager implements IFloodlightModule, ITopologyService, IRo ...@@ -854,6 +859,7 @@ public class TopologyManager implements IFloodlightModule, ITopologyService, IRo
topologyAware = new ArrayList<ITopologyListener>(); topologyAware = new ArrayList<ITopologyListener>();
ldUpdates = new LinkedBlockingQueue<LDUpdate>(); ldUpdates = new LinkedBlockingQueue<LDUpdate>();
haListener = new HAListenerDelegate(); haListener = new HAListenerDelegate();
this.decisionChangedListeners = new ArrayList<IRoutingDecisionChangedListener>();
registerTopologyDebugCounters(); registerTopologyDebugCounters();
registerTopologyDebugEvents(); registerTopologyDebugEvents();
} }
...@@ -1531,4 +1537,19 @@ public class TopologyManager implements IFloodlightModule, ITopologyService, IRo ...@@ -1531,4 +1537,19 @@ public class TopologyManager implements IFloodlightModule, ITopologyService, IRo
return ports; return ports;
} }
public void addRoutingDecisionChangedListener(IRoutingDecisionChangedListener listener) {
decisionChangedListeners.add(listener);
}
public void removeRoutingDecisionChangedListener(IRoutingDecisionChangedListener listener) {
decisionChangedListeners.remove(listener);
}
public void handleRoutingDecisionChange(Iterable<Masked<U64>> event) {
for(IRoutingDecisionChangedListener listener : decisionChangedListeners) {
listener.routingDecisionChanged(event);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment