net.floodlightcontroller.virtualnetwork
Class VirtualNetworkFilter

java.lang.Object
  extended by net.floodlightcontroller.virtualnetwork.VirtualNetworkFilter
All Implemented Interfaces:
IListener<OFType>, IOFMessageListener, IFloodlightModule, IFloodlightService, IVirtualNetworkService

public class VirtualNetworkFilter
extends java.lang.Object
implements IFloodlightModule, IVirtualNetworkService, IOFMessageListener

A simple Layer 2 (MAC based) network virtualization module. This module allows you to create simple L2 networks (host + gateway) and will drop traffic if they are not on the same virtual network. LIMITATIONS - This module does not allow overlapping of IPs or MACs - You can only have 1 gateway per virtual network (can be shared) - There is filtering of multicast/broadcast traffic - All DHCP traffic will be allowed, regardless of unicast/broadcast

Author:
alexreimers

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.floodlightcontroller.core.IListener
IListener.Command
 
Field Summary
protected  net.floodlightcontroller.virtualnetwork.VirtualNetworkFilter.DeviceListenerImpl deviceListener
           
protected  java.util.Map<java.lang.Integer,java.util.Set<java.lang.String>> gatewayToGuid
           
protected  java.util.Map<java.lang.String,java.lang.Integer> guidToGateway
           
protected static org.slf4j.Logger log
           
protected  java.util.Map<MACAddress,java.lang.Integer> macToGateway
           
protected  java.util.Map<MACAddress,java.lang.String> macToGuid
           
protected  java.util.Map<java.lang.String,java.lang.String> nameToGuid
           
protected  java.util.Map<java.lang.String,MACAddress> portToMac
           
protected  java.util.Map<java.lang.String,VirtualNetwork> vNetsByGuid
           
 
Constructor Summary
VirtualNetworkFilter()
           
 
Method Summary
protected  void addGateway(java.lang.String guid, java.lang.Integer ip)
          Adds a gateway to a virtual network.
 void addHost(MACAddress mac, java.lang.String guid, java.lang.String port)
          Adds a host to a virtual network.
 void createNetwork(java.lang.String guid, java.lang.String network, java.lang.Integer gateway)
          Creates a new virtual network.
protected  void deleteGateway(java.lang.String guid)
          Deletes a gateway for a virtual network.
 void deleteHost(MACAddress mac, java.lang.String port)
          Deletes a host from a virtual network.
 void deleteNetwork(java.lang.String guid)
          Deletes a virtual network.
protected  void doDropFlow(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx)
          Writes a FlowMod to a switch that inserts a drop flow.
 java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleDependencies()
          Get a list of Modules that this module depends on.
 java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleServices()
          Return the list of interfaces that this module implements.
 java.lang.String getName()
          The name assigned to this listener
 java.util.Map<java.lang.Class<? extends IFloodlightService>,IFloodlightService> getServiceImpls()
          Instantiate (as needed) and return objects that implement each of the services exported by this module.
 void init(FloodlightModuleContext context)
          This is a hook for each module to do its internal initialization, e.g., call setService(context.getService("Service")) All module dependencies are resolved when this is called, but not every module is initialized.
 boolean isCallbackOrderingPostreq(OFType type, java.lang.String name)
          Check if the module called name is a callback ordering post-requisite for this module.
 boolean isCallbackOrderingPrereq(OFType type, java.lang.String name)
          Check if the module called name is a callback ordering prerequisite for this module.
protected  boolean isDefaultGateway(Ethernet frame)
          Checks whether the frame is destined to or from a gateway.
protected  boolean isDhcpPacket(Ethernet frame)
          Checks to see if an Ethernet frame is a DHCP packet.
 java.util.Collection<VirtualNetwork> listNetworks()
          Return list of all virtual networks.
protected  boolean oneSameNetwork(MACAddress m1, MACAddress m2)
          Checks to see if two MAC Addresses are on the same network.
protected  IListener.Command processPacketIn(IOFSwitch sw, OFPacketIn msg, FloodlightContext cntx)
          Processes an OFPacketIn message and decides if the OFPacketIn should be dropped or the processing should continue.
 IListener.Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx)
          This is the method Floodlight uses to call listeners with OpenFlow messages
 void startUp(FloodlightModuleContext context)
          This is a hook for each module to do its external initializations, e.g., register for callbacks or query for state in other modules It is expected that this function will not block and that modules that want non-event driven CPU will spawn their own threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.slf4j.Logger log

vNetsByGuid

protected java.util.Map<java.lang.String,VirtualNetwork> vNetsByGuid

nameToGuid

protected java.util.Map<java.lang.String,java.lang.String> nameToGuid

guidToGateway

protected java.util.Map<java.lang.String,java.lang.Integer> guidToGateway

gatewayToGuid

protected java.util.Map<java.lang.Integer,java.util.Set<java.lang.String>> gatewayToGuid

macToGateway

protected java.util.Map<MACAddress,java.lang.Integer> macToGateway

macToGuid

protected java.util.Map<MACAddress,java.lang.String> macToGuid

portToMac

protected java.util.Map<java.lang.String,MACAddress> portToMac

deviceListener

protected net.floodlightcontroller.virtualnetwork.VirtualNetworkFilter.DeviceListenerImpl deviceListener
Constructor Detail

VirtualNetworkFilter

public VirtualNetworkFilter()
Method Detail

addGateway

protected void addGateway(java.lang.String guid,
                          java.lang.Integer ip)
Adds a gateway to a virtual network.

Parameters:
guid - The ID (not name) of the network.
ip - The IP addresses of the gateway.

deleteGateway

protected void deleteGateway(java.lang.String guid)
Deletes a gateway for a virtual network.

Parameters:
guid - The ID (not name) of the network to delete the gateway for.

createNetwork

public void createNetwork(java.lang.String guid,
                          java.lang.String network,
                          java.lang.Integer gateway)
Description copied from interface: IVirtualNetworkService
Creates a new virtual network. This can also be called to modify a virtual network. To update a network you specify the GUID and the fields you want to update.

Specified by:
createNetwork in interface IVirtualNetworkService
Parameters:
guid - The ID of the network. Must be unique.
network - The network name. Must be unique.
gateway - The IP address of the network gateway, null if none.

deleteNetwork

public void deleteNetwork(java.lang.String guid)
Description copied from interface: IVirtualNetworkService
Deletes a virtual network.

Specified by:
deleteNetwork in interface IVirtualNetworkService
Parameters:
guid - The ID (not name) of virtual network to delete.

addHost

public void addHost(MACAddress mac,
                    java.lang.String guid,
                    java.lang.String port)
Description copied from interface: IVirtualNetworkService
Adds a host to a virtual network. If a mapping already exists the new one will override the old mapping.

Specified by:
addHost in interface IVirtualNetworkService
Parameters:
mac - The MAC address of the host to add.
guid - The network to add the host to.
port - The logical port name to attach the host to. Must be unique.

deleteHost

public void deleteHost(MACAddress mac,
                       java.lang.String port)
Description copied from interface: IVirtualNetworkService
Deletes a host from a virtual network. Either the MAC or Port must be specified.

Specified by:
deleteHost in interface IVirtualNetworkService
Parameters:
mac - The MAC address to delete.
port - The logical port the host is attached to.

getModuleServices

public java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleServices()
Description copied from interface: IFloodlightModule
Return the list of interfaces that this module implements. All interfaces must inherit IFloodlightService

Specified by:
getModuleServices in interface IFloodlightModule
Returns:

getServiceImpls

public java.util.Map<java.lang.Class<? extends IFloodlightService>,IFloodlightService> getServiceImpls()
Description copied from interface: IFloodlightModule
Instantiate (as needed) and return objects that implement each of the services exported by this module. The map returned maps the implemented service to the object. The object could be the same object or different objects for different exported services.

Specified by:
getServiceImpls in interface IFloodlightModule
Returns:
The map from service interface class to service implementation

getModuleDependencies

public java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleDependencies()
Description copied from interface: IFloodlightModule
Get a list of Modules that this module depends on. The module system will ensure that each these dependencies is resolved before the subsequent calls to init().

Specified by:
getModuleDependencies in interface IFloodlightModule
Returns:
The Collection of IFloodlightServices that this module depends on.

init

public void init(FloodlightModuleContext context)
          throws FloodlightModuleException
Description copied from interface: IFloodlightModule
This is a hook for each module to do its internal initialization, e.g., call setService(context.getService("Service")) All module dependencies are resolved when this is called, but not every module is initialized.

Specified by:
init in interface IFloodlightModule
Throws:
FloodlightModuleException

startUp

public void startUp(FloodlightModuleContext context)
Description copied from interface: IFloodlightModule
This is a hook for each module to do its external initializations, e.g., register for callbacks or query for state in other modules It is expected that this function will not block and that modules that want non-event driven CPU will spawn their own threads.

Specified by:
startUp in interface IFloodlightModule

getName

public java.lang.String getName()
Description copied from interface: IListener
The name assigned to this listener

Specified by:
getName in interface IListener<OFType>
Returns:

isCallbackOrderingPrereq

public boolean isCallbackOrderingPrereq(OFType type,
                                        java.lang.String name)
Description copied from interface: IListener
Check if the module called name is a callback ordering prerequisite for this module. In other words, if this function returns true for the given name, then this listener will be called after that message listener.

Specified by:
isCallbackOrderingPrereq in interface IListener<OFType>
Parameters:
type - the object type to which this applies
name - the name of the module
Returns:
whether name is a prerequisite.

isCallbackOrderingPostreq

public boolean isCallbackOrderingPostreq(OFType type,
                                         java.lang.String name)
Description copied from interface: IListener
Check if the module called name is a callback ordering post-requisite for this module. In other words, if this function returns true for the given name, then this listener will be called before that message listener.

Specified by:
isCallbackOrderingPostreq in interface IListener<OFType>
Parameters:
type - the object type to which this applies
name - the name of the module
Returns:
whether name is a post-requisite.

receive

public IListener.Command receive(IOFSwitch sw,
                                 OFMessage msg,
                                 FloodlightContext cntx)
Description copied from interface: IOFMessageListener
This is the method Floodlight uses to call listeners with OpenFlow messages

Specified by:
receive in interface IOFMessageListener
Parameters:
sw - the OpenFlow switch that sent this message
msg - the message
cntx - a Floodlight message context object you can use to pass information between listeners
Returns:
the command to continue or stop the execution

isDefaultGateway

protected boolean isDefaultGateway(Ethernet frame)
Checks whether the frame is destined to or from a gateway.

Parameters:
frame - The ethernet frame to check.
Returns:
True if it is to/from a gateway, false otherwise.

oneSameNetwork

protected boolean oneSameNetwork(MACAddress m1,
                                 MACAddress m2)
Checks to see if two MAC Addresses are on the same network.

Parameters:
m1 - The first MAC.
m2 - The second MAC.
Returns:
True if they are on the same virtual network, false otherwise.

isDhcpPacket

protected boolean isDhcpPacket(Ethernet frame)
Checks to see if an Ethernet frame is a DHCP packet.

Parameters:
frame - The Ethernet frame.
Returns:
True if it is a DHCP frame, false otherwise.

processPacketIn

protected IListener.Command processPacketIn(IOFSwitch sw,
                                            OFPacketIn msg,
                                            FloodlightContext cntx)
Processes an OFPacketIn message and decides if the OFPacketIn should be dropped or the processing should continue.

Parameters:
sw - The switch the PacketIn came from.
msg - The OFPacketIn message from the switch.
cntx - The FloodlightContext for this message.
Returns:
Command.CONTINUE if processing should be continued, Command.STOP otherwise.

doDropFlow

protected void doDropFlow(IOFSwitch sw,
                          OFPacketIn pi,
                          FloodlightContext cntx)
Writes a FlowMod to a switch that inserts a drop flow.

Parameters:
sw - The switch to write the FlowMod to.
pi - The corresponding OFPacketIn. Used to create the OFMatch structure.
cntx - The FloodlightContext that gets passed to the switch.

listNetworks

public java.util.Collection<VirtualNetwork> listNetworks()
Description copied from interface: IVirtualNetworkService
Return list of all virtual networks.

Specified by:
listNetworks in interface IVirtualNetworkService
Returns:
Collection