Java 类net.floodlightcontroller.core.FloodlightContext 实例源码
项目:open-kilda
文件:PathVerificationFlowTest.java
@Before
public void setUp() throws Exception {
logger = LoggerFactory.getLogger(PathVerificationFlowTest.class);
cntx = new FloodlightContext();
FloodlightModuleContext fmc = new FloodlightModuleContext();
fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
swDescription = factory.buildDescStatsReply().build();
swFeatures = factory.buildFeaturesReply().setNBuffers(1000).build();
sw = EasyMock.createMock(IOFSwitch.class);
expect(sw.getId()).andReturn(swDpid).anyTimes();
expect(sw.getOFFactory()).andReturn(factory).anyTimes();
expect(sw.getBuffers()).andReturn(swFeatures.getNBuffers()).anyTimes();
expect(sw.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
expect(sw.getSwitchDescription()).andReturn(new SwitchDescription(swDescription)).anyTimes();
expect(sw.isActive()).andReturn(true).anyTimes();
expect(sw.getLatency()).andReturn(U64.of(10L)).anyTimes();
replay(sw);
pvs = new PathVerificationService();
}
项目:open-kilda
文件:MockFloodlightProvider.java
public void dispatchMessage(IOFSwitch sw, OFMessage msg, FloodlightContext bc) {
List<IOFMessageListener> theListeners = listeners.get(msg.getType()).getOrderedListeners();
if (theListeners != null) {
Command result = Command.CONTINUE;
Iterator<IOFMessageListener> it = theListeners.iterator();
if (OFType.PACKET_IN.equals(msg.getType())) {
OFPacketIn pi = (OFPacketIn)msg;
Ethernet eth = new Ethernet();
eth.deserialize(pi.getData(), 0, pi.getData().length);
IFloodlightProviderService.bcStore.put(bc,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
}
while (it.hasNext() && !Command.STOP.equals(result)) {
result = it.next().receive(sw, msg, bc);
}
}
// paag
for (IControllerCompletionListener listener:completionListeners)
listener.onMessageConsumed(sw, msg, bc);
}
项目:iTAP-controller
文件:MockFloodlightProvider.java
@Override
public void handleOutgoingMessage(IOFSwitch sw, OFMessage m) {
FloodlightContext bc = new FloodlightContext();
List<IOFMessageListener> msgListeners = null;
if (listeners.containsKey(m.getType())) {
msgListeners = listeners.get(m.getType()).getOrderedListeners();
}
if (msgListeners != null) {
for (IOFMessageListener listener : msgListeners) {
if (Command.STOP.equals(listener.receive(sw, m, bc))) {
break;
}
}
}
}
项目:fresco_floodlight
文件:FP_LibFloodlight.java
@Override
public int getSrcIP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPv4Address srcIP;
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
srcIP = ipv4.getSourceAddress();
return srcIP.getInt();
}
else if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
srcIP = arp.getSenderProtocolAddress();
return srcIP.getInt();
}
//for other packets without source IP information
return 0;
}
项目:fresco_floodlight
文件:FP_LibFloodlight.java
@Override
public int getDstIP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPv4Address dstIP;
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
dstIP = ipv4.getDestinationAddress();
return dstIP.getInt();
}
else if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
dstIP = arp.getTargetProtocolAddress();
return dstIP.getInt();
}
//for other packets without destination IP information
return 0;
}
项目:fresco_floodlight
文件:FP_LibFloodlight.java
@Override
public long getARPSenderMAC(FPContext cntx){
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
MacAddress senderMAC;
if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
senderMAC = arp.getSenderHardwareAddress();
return senderMAC.getLong();
}
//for other non-arp packets
return 0;
}
项目:iTAP-controller
文件:LearningSwitch.java
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
// The packet in match will only contain the port number.
// We need to add in specifics for the hosts we're routing between.
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
MacAddress srcMac = eth.getSourceMACAddress();
MacAddress dstMac = eth.getDestinationMACAddress();
Match.Builder mb = sw.getOFFactory().buildMatch();
mb.setExact(MatchField.IN_PORT, inPort)
.setExact(MatchField.ETH_SRC, srcMac)
.setExact(MatchField.ETH_DST, dstMac);
if (!vlan.equals(VlanVid.ZERO)) {
mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
}
return mb.build();
}
项目:iTAP-controller
文件:ObfuscationController.java
@Override
public net.floodlightcontroller.core.IListener.Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
oTopologyManager.updateTopologyMappings(sw, (OFPacketIn) msg, cntx);
//log.debug("receive {}",eth);
if ((eth.getPayload() instanceof ARP)) {
handleARP(sw, (OFPacketIn) msg, cntx);
}
else if (eth.getPayload() instanceof IPv4) {
handleIP(sw, (OFPacketIn) msg, cntx);
}
else {
//handleCbench(sw, (OFPacketIn) msg, cntx);
//log.warn("could not handle packet {}",eth.toString());
}
return Command.CONTINUE;
}
项目:iTAP-controller
文件:Hub.java
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
OFMessage outMessage;
HubType ht = HubType.USE_PACKET_OUT;
switch (ht) {
case USE_FLOW_MOD:
outMessage = createHubFlowMod(sw, msg);
break;
default:
case USE_PACKET_OUT:
outMessage = createHubPacketOut(sw, msg);
break;
}
sw.write(outMessage);
return Command.CONTINUE;
}
项目:fresco_floodlight
文件:LearningSwitch.java
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
// The packet in match will only contain the port number.
// We need to add in specifics for the hosts we're routing between.
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
MacAddress srcMac = eth.getSourceMACAddress();
MacAddress dstMac = eth.getDestinationMACAddress();
Match.Builder mb = sw.getOFFactory().buildMatch();
mb.setExact(MatchField.IN_PORT, inPort)
.setExact(MatchField.ETH_SRC, srcMac)
.setExact(MatchField.ETH_DST, dstMac);
if (!vlan.equals(VlanVid.ZERO)) {
mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
}
return mb.build();
}
项目:iTAP-controller
文件:PktInProcessingTime.java
@Override
@LogMessageDoc(level="WARN",
message="Time to process packet-in exceeded threshold: {}",
explanation="Time to process packet-in exceeded the configured " +
"performance threshold",
recommendation=LogMessageDoc.CHECK_CONTROLLER)
public void recordEndTimePktIn(IOFSwitch sw, OFMessage m, FloodlightContext cntx) {
if (isEnabled()) {
long procTimeNs = System.nanoTime() - startTimePktNs;
ctb.updatePerPacketCounters(procTimeNs);
if (ptWarningThresholdInNano > 0 &&
procTimeNs > ptWarningThresholdInNano) {
logger.warn("Time to process packet-in exceeded threshold: {}",
procTimeNs/1000);
}
}
}
项目:iTAP-controller
文件:TopologyManager.java
/**
* If the packet-in switch port is disabled for all data traffic, then
* the packet will be dropped. Otherwise, the packet will follow the
* normal processing chain.
* @param sw
* @param pi
* @param cntx
* @return
*/
protected Command dropFilter(DatapathId sw, OFPacketIn pi,
FloodlightContext cntx) {
Command result = Command.CONTINUE;
OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));
// If the input port is not allowed for data traffic, drop everything.
// BDDP packets will not reach this stage.
if (isAllowed(sw, inPort) == false) {
if (log.isTraceEnabled()) {
log.trace("Ignoring packet because of topology " +
"restriction on switch={}, port={}", sw.getLong(), inPort.getPortNumber());
result = Command.STOP;
}
}
return result;
}
项目:fresco_floodlight
文件:TopologyManager.java
/**
* If the packet-in switch port is disabled for all data traffic, then
* the packet will be dropped. Otherwise, the packet will follow the
* normal processing chain.
* @param sw
* @param pi
* @param cntx
* @return
*/
protected Command dropFilter(DatapathId sw, OFPacketIn pi,
FloodlightContext cntx) {
Command result = Command.CONTINUE;
OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));
// If the input port is not allowed for data traffic, drop everything.
// BDDP packets will not reach this stage.
if (isAllowed(sw, inPort) == false) {
if (log.isTraceEnabled()) {
log.trace("Ignoring packet because of topology " +
"restriction on switch={}, port={}", sw.getLong(), inPort.getPortNumber());
result = Command.STOP;
}
}
return result;
}
项目:fresco_floodlight
文件:TopologyManager.java
protected Command processPacketInMessage(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
// get the packet-in switch.
Ethernet eth =
IFloodlightProviderService.bcStore.
get(cntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if (eth.getPayload() instanceof BSN) {
BSN bsn = (BSN) eth.getPayload();
if (bsn == null) return Command.STOP;
if (bsn.getPayload() == null) return Command.STOP;
// It could be a packet other than BSN LLDP, therefore
// continue with the regular processing.
if (bsn.getPayload() instanceof LLDP == false)
return Command.CONTINUE;
doFloodBDDP(sw.getId(), pi, cntx);
return Command.STOP;
} else {
return dropFilter(sw.getId(), pi, cntx);
}
}
项目:fresco_floodlight
文件:Controller.java
@Override
public void handleOutgoingMessage(IOFSwitch sw, OFMessage m) {
if (sw == null)
throw new NullPointerException("Switch must not be null");
if (m == null)
throw new NullPointerException("OFMessage must not be null");
FloodlightContext bc = new FloodlightContext();
List<IOFMessageListener> listeners = null;
if (messageListeners.containsKey(m.getType())) {
listeners = messageListeners.get(m.getType()).getOrderedListeners();
}
if (listeners != null) {
for (IOFMessageListener listener : listeners) {
if (Command.STOP.equals(listener.receive(sw, m, bc))) {
break;
}
}
}
}
项目:iTAP-controller
文件:ObfuscationSwitchStateManager.java
@Override
public net.floodlightcontroller.core.IListener.Command receive(
IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
System.out.println("flow expired: "+sw.toString() + msg.toString());
//OFFlowRemoved flowRemoved = (OFFlowRemoved) msg;
if (!switchStates.containsKey(sw))
switchStates.put(sw, new ObfuscationSwitchState(sw));
if (msg.getType() == OFType.FLOW_REMOVED) {
OFFlowRemoved flowRemoved = (OFFlowRemoved) msg;
System.out.println("flow expired: "+sw.toString() + "dst: " + flowRemoved.getCookie());
long dst = flowRemoved.getCookie().getValue();
ObfuscationHeader oHeader = new ObfuscationHeader();
Match match = flowRemoved.getMatch();
switchStates.get(sw).removeDestinationID(dst);
}
return Command.CONTINUE;
}
项目:open-kilda
文件:SwitchManager.java
/**
* {@inheritDoc}
*/
@Override
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
logger.debug("OF_ERROR: {}", msg);
// TODO: track xid for flow id
if (OFType.ERROR.equals(msg.getType())) {
ErrorMessage error = new ErrorMessage(
new ErrorData(ErrorType.INTERNAL_ERROR, ((OFErrorMsg) msg).getErrType().toString(), null),
System.currentTimeMillis(), DEFAULT_CORRELATION_ID, Destination.WFM_TRANSACTION);
// TODO: Most/all commands are flow related, but not all. 'kilda.flow' might
// not be the best place to send a generic error.
kafkaProducer.postMessage("kilda.flow", error);
}
return Command.CONTINUE;
}
项目:open-kilda
文件:PathVerificationService.java
@Override
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext context) {
switch (msg.getType()) {
case PACKET_IN:
return handlePacketIn(sw, (OFPacketIn) msg, context);
default:
break;
}
return Command.CONTINUE;
}
项目:open-kilda
文件:PathVerificationPacketSignTest.java
@Before
public void setUp() throws Exception {
super.setUp();
OFPacketOut packetOut = pvs.generateVerificationPacket(sw1, OFPort.of(1));
ofPacketIn = EasyMock.createMock(OFPacketIn.class);
context = new FloodlightContext();
expect(ofPacketIn.getType()).andReturn(OFType.PACKET_IN).anyTimes();
expect(ofPacketIn.getXid()).andReturn(0L).anyTimes();
expect(ofPacketIn.getVersion()).andReturn(packetOut.getVersion()).anyTimes();
Match match = EasyMock.createMock(Match.class);
expect(match.get(MatchField.IN_PORT)).andReturn(OFPort.of(1)).anyTimes();
replay(match);
expect(ofPacketIn.getMatch()).andReturn(match).anyTimes();
replay(ofPacketIn);
IPacket expected = new Ethernet().deserialize(packetOut.getData(), 0,
packetOut.getData().length);
context.getStorage().put(IFloodlightProviderService.CONTEXT_PI_PAYLOAD, expected);
HashMap<DatapathId, IOFSwitch> switches = new HashMap<>();
switches.put(sw1.getId(), sw1);
switches.put(sw2.getId(), sw2);
mockSwitchManager.setSwitches(switches);
reset(producer);
pvs.setKafkaProducer(producer);
}
项目:open-kilda
文件:PathVerificationPacketOutTest.java
@Before
public void setUp() throws Exception {
super.setUp();
cntx = new FloodlightContext();
FloodlightModuleContext fmc = new FloodlightModuleContext();
fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
fmc.addService(IOFSwitchService.class, getMockSwitchService());
swDescription = factory.buildDescStatsReply().build();
pvs = new PathVerificationService();
pvs.initAlgorithm("secret");
srcIpTarget = new InetSocketAddress("192.168.10.1", 200);
dstIpTarget = new InetSocketAddress("192.168.10.101", 100);
sw1HwAddrTarget = "11:22:33:44:55:66";
sw2HwAddrTarget = "AA:BB:CC:DD:EE:FF";
OFPortDesc sw1Port1 = EasyMock.createMock(OFPortDesc.class);
expect(sw1Port1.getHwAddr()).andReturn(MacAddress.of(sw1HwAddrTarget)).anyTimes();
OFPortDesc sw2Port1 = EasyMock.createMock(OFPortDesc.class);
expect(sw2Port1.getHwAddr()).andReturn(MacAddress.of(sw2HwAddrTarget)).anyTimes();
replay(sw1Port1);
replay(sw2Port1);
sw1 = buildMockIOFSwitch(1L, sw1Port1, factory, swDescription, srcIpTarget);
sw2 = buildMockIOFSwitch(2L, sw2Port1, factory, swDescription, dstIpTarget);
replay(sw1);
replay(sw2);
}
项目:open-kilda
文件:FloodlightTestCase.java
public static FloodlightContext parseAndAnnotate(FloodlightContext bc, OFMessage m) {
if (OFType.PACKET_IN.equals(m.getType())) {
OFPacketIn pi = (OFPacketIn)m;
Ethernet eth = new Ethernet();
eth.deserialize(pi.getData(), 0, pi.getData().length);
IFloodlightProviderService.bcStore.put(bc,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
}
return bc;
}
项目:fresco_floodlight
文件:SecurityKernel.java
@Override
public net.floodlightcontroller.core.IListener.Command receive(IOFSwitch sw, OFMessage msg,
FloodlightContext cntx) {
switch (msg.getType()) {
case FLOW_REMOVED:
return this.handleFlowRemovedMessage(sw, (OFFlowRemoved) msg);
default:
return Command.CONTINUE;
}
}
项目:iTAP-controller
文件:DeviceManagerImplTest.java
private Command dispatchPacketIn(long swId, OFPacketIn pi,
FloodlightContext cntx) {
IOFSwitch sw = getMockSwitchService().getSwitch(DatapathId.of(swId));
Ethernet eth = new Ethernet();
eth.deserialize(pi.getData(), 0, pi.getData().length);
IFloodlightProviderService.bcStore.put(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
return deviceManager.receive(sw, pi, cntx);
}
项目:fresco_floodlight
文件:FP_LibFloodlight.java
@Override
public boolean isUDP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
return (ipv4.getProtocol() == IpProtocol.UDP);
}
else
{
return false;
}
}
项目:fresco_floodlight
文件:FP_LibFloodlight.java
@Override
public int getDstPort(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
if( isTCP(cntx) )
{
TCP tcp = (TCP) ipv4.getPayload();
return tcp.getDestinationPort().getPort();
}
else if ( isUDP(cntx) )
{
UDP udp = (UDP) ipv4.getPayload();
return udp.getDestinationPort().getPort();
}
else
{
return 0;
}
}
else
{
return 0;
}
}
项目:fresco_floodlight
文件:FP_LibFloodlight.java
@Override
public int getSrcPort(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
if( isTCP(cntx) )
{
TCP tcp = (TCP) ipv4.getPayload();
return tcp.getSourcePort().getPort();
}
else if ( isUDP(cntx) )
{
UDP udp = (UDP) ipv4.getPayload();
return udp.getSourcePort().getPort();
}
else
{
return 0;
}
}
else
{
return 0;
}
}
项目:iTAP-controller
文件:ForwardingBase.java
@Override
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
switch (msg.getType()) {
case PACKET_IN:
IRoutingDecision decision = null;
if (cntx != null) {
decision = RoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
}
return this.processPacketInMessage(sw, (OFPacketIn) msg, decision, cntx);
default:
break;
}
return Command.CONTINUE;
}
项目:iTAP-controller
文件:VirtualNetworkFilter.java
/**
* Processes an OFPacketIn message and decides if the OFPacketIn should be dropped
* or the processing should continue.
* @param sw The switch the PacketIn came from.
* @param msg The OFPacketIn message from the switch.
* @param cntx The FloodlightContext for this message.
* @return Command.CONTINUE if processing should be continued, Command.STOP otherwise.
*/
protected Command processPacketIn(IOFSwitch sw, OFPacketIn msg, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
Command ret = Command.STOP;
String srcNetwork = macToGuid.get(eth.getSourceMACAddress());
// If the host is on an unknown network we deny it.
// We make exceptions for ARP and DHCP.
if (eth.isBroadcast() || eth.isMulticast() || isDefaultGateway(eth) || isDhcpPacket(eth)) {
ret = Command.CONTINUE;
} else if (srcNetwork == null) {
log.trace("Blocking traffic from host {} because it is not attached to any network.",
eth.getSourceMACAddress().toString());
ret = Command.STOP;
} else if (oneSameNetwork(eth.getSourceMACAddress(), eth.getDestinationMACAddress())) {
// if they are on the same network continue
ret = Command.CONTINUE;
}
if (log.isTraceEnabled())
log.trace("Results for flow between {} and {} is {}",
new Object[] {eth.getSourceMACAddress(), eth.getDestinationMACAddress(), ret});
/*
* TODO - figure out how to still detect gateways while using
* drop mods
if (ret == Command.STOP) {
if (!(eth.getPayload() instanceof ARP))
doDropFlow(sw, msg, cntx);
}
*/
return ret;
}
项目:iTAP-controller
文件:PortDownReconciliation.java
@Override
public
void
init(FloodlightModuleContext context)
throws FloodlightModuleException {
switchService = context.getServiceImpl(IOFSwitchService.class);
topology = context.getServiceImpl(ITopologyService.class);
frm = context.getServiceImpl(IFlowReconcileService.class);
lds = context.getServiceImpl(ILinkDiscoveryService.class);
cntx = new FloodlightContext();
}
项目:iTAP-controller
文件:DeviceManagerImpl.java
@Override
public Command receive(IOFSwitch sw, OFMessage msg,
FloodlightContext cntx) {
switch (msg.getType()) {
case PACKET_IN:
cntIncoming.increment();
return this.processPacketInMessage(sw, (OFPacketIn) msg, cntx);
default:
break;
}
return Command.CONTINUE;
}
项目:fresco_floodlight
文件:PktInProcessingTime.java
@Override
public void recordEndTimePktIn(IOFSwitch sw, OFMessage m, FloodlightContext cntx) {
if (isEnabled()) {
long procTimeNs = System.nanoTime() - startTimePktNs;
ctb.updatePerPacketCounters(procTimeNs);
if (ptWarningThresholdInNano > 0 &&
procTimeNs > ptWarningThresholdInNano) {
logger.warn("Time to process packet-in exceeded threshold: {}",
procTimeNs/1000);
}
}
}
项目:fresco_floodlight
文件:DeviceManagerImpl.java
@Override
public Command receive(IOFSwitch sw, OFMessage msg,
FloodlightContext cntx) {
switch (msg.getType()) {
case PACKET_IN:
cntIncoming.increment();
return this.processPacketInMessage(sw, (OFPacketIn) msg, cntx);
default:
break;
}
return Command.CONTINUE;
}
项目:iTAP-controller
文件:LearningSwitch.java
@Override
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
switch (msg.getType()) {
case PACKET_IN:
return this.processPacketInMessage(sw, (OFPacketIn) msg, cntx);
case FLOW_REMOVED:
return this.processFlowRemovedMessage(sw, (OFFlowRemoved) msg);
case ERROR:
log.info("received an error {} from switch {}", msg, sw);
return Command.CONTINUE;
default:
log.error("received an unexpected message {} from switch {}", msg, sw);
return Command.CONTINUE;
}
}
项目:iTAP-controller
文件:ObfuscationController.java
private void handleARP(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if (! (eth.getPayload() instanceof ARP)) // not an ARP packet
return;
ARP arpRequest = (ARP) eth.getPayload();
if (arpRequest.getOpCode() == ARP.OP_REPLY) { // is a reply
oTopologyManager.updateTopologyMappings(sw, pi, cntx);
for (ARP pendingArpRequest : arpRequestBuffer.getPendingRequests(IPv4Address.of(arpRequest.getSenderProtocolAddress()))) {
if (oTopologyManager.knowSwitchForIp(IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()))) {
SwitchHostInfo dstSwitchPort = oTopologyManager.getSwitchForIp(IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()));
sendArpReply(MacAddress.of(arpRequest.getSenderHardwareAddress()), IPv4Address.of(arpRequest.getSenderProtocolAddress()), MacAddress.of(pendingArpRequest.getSenderHardwareAddress()), IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()), dstSwitchPort.getSwitch(), dstSwitchPort.getPort());
arpRequestBuffer.removeRequest(pendingArpRequest);
}
else
log.warn("answering pending ARP request failed because dst switch/port is not known. {}",pendingArpRequest);
}
}
else { // is a request
if (IPv4Address.of(arpRequest.getSenderProtocolAddress()).toString().contentEquals("10.0.0.111")) // ignore crafted requests from switches
return;
if (oTopologyManager.knowMacForIp(IPv4Address.of(arpRequest.getTargetProtocolAddress()))) {
MacAddress senderMac = oTopologyManager.getMacForIp(IPv4Address.of(arpRequest.getTargetProtocolAddress()));
sendArpReply(senderMac, IPv4Address.of(arpRequest.getTargetProtocolAddress()), MacAddress.of(arpRequest.getSenderHardwareAddress()), IPv4Address.of(arpRequest.getSenderProtocolAddress()), sw, pi.getMatch().get(MatchField.IN_PORT));
}
else {
arpRequestBuffer.addRequest(arpRequest);
for (DatapathId swi : switchService.getAllSwitchDpids())
floodArpRequest(switchService.getSwitch(swi),IPv4Address.of(arpRequest.getTargetProtocolAddress()));
}
}
}
项目:fresco_floodlight
文件:Forwarding.java
/**
* Creates a OFPacketOut with the OFPacketIn data that is flooded on all ports unless
* the port is blocked, in which case the packet will be dropped.
* @param sw The switch that receives the OFPacketIn
* @param pi The OFPacketIn that came to the switch
* @param cntx The FloodlightContext associated with this OFPacketIn
*/
protected void doFlood(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));
// Set Action to flood
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
List<OFAction> actions = new ArrayList<OFAction>();
Set<OFPort> broadcastPorts = this.topologyService.getSwitchBroadcastPorts(sw.getId());
if (broadcastPorts == null) {
log.debug("BroadcastPorts returned null. Assuming single switch w/no links.");
/* Must be a single-switch w/no links */
broadcastPorts = Collections.singleton(OFPort.FLOOD);
}
for (OFPort p : broadcastPorts) {
if (p.equals(inPort)) continue;
actions.add(sw.getOFFactory().actions().output(p, Integer.MAX_VALUE));
}
pob.setActions(actions);
// log.info("actions {}",actions);
// set buffer-id, in-port and packet-data based on packet-in
pob.setBufferId(OFBufferId.NO_BUFFER);
pob.setInPort(inPort);
pob.setData(pi.getData());
try {
if (log.isTraceEnabled()) {
log.trace("Writing flood PacketOut switch={} packet-in={} packet-out={}",
new Object[] {sw, pi, pob.build()});
}
messageDamper.write(sw, pob.build());
} catch (IOException e) {
log.error("Failure writing PacketOut switch={} packet-in={} packet-out={}",
new Object[] {sw, pi, pob.build()}, e);
}
return;
}
项目:iTAP-controller
文件:VirtualNetworkFilterTest.java
@Test
public void testDefaultGateway() {
testAddHost();
IOFMessageListener listener = getVirtualNetworkListener();
cntx = new FloodlightContext();
IFloodlightProviderService.bcStore.put(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
(Ethernet)mac1ToGwPacketIntestPacket);
deviceService.learnEntity(((Ethernet)mac1ToGwPacketIntestPacket).getDestinationMACAddress().getLong(),
null, IPv4.toIPv4Address(gw1), null, null);
Command ret = listener.receive(sw1, mac1ToGwPacketIn, cntx);
assertTrue(ret == Command.CONTINUE);
}
项目:fresco_floodlight
文件:ForwardingBase.java
@Override
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
switch (msg.getType()) {
case PACKET_IN:
IRoutingDecision decision = null;
if (cntx != null) {
decision = RoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
}
return this.processPacketInMessage(sw, (OFPacketIn) msg, decision, cntx);
default:
break;
}
return Command.CONTINUE;
}
项目:fresco_floodlight
文件:ForwardingBase.java
/**
* Write packetout message to sw with output actions to one or more
* output ports with inPort/outPorts passed in.
* @param packetData
* @param sw
* @param inPort
* @param ports
* @param cntx
*/
public void packetOutMultiPort(byte[] packetData, IOFSwitch sw,
OFPort inPort, Set<OFPort> outPorts, FloodlightContext cntx) {
//setting actions
List<OFAction> actions = new ArrayList<OFAction>();
Iterator<OFPort> j = outPorts.iterator();
while (j.hasNext()) {
actions.add(sw.getOFFactory().actions().output(j.next(), 0));
}
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
pob.setActions(actions);
pob.setBufferId(OFBufferId.NO_BUFFER);
pob.setInPort(inPort);
pob.setData(packetData);
try {
if (log.isTraceEnabled()) {
log.trace("write broadcast packet on switch-id={} " +
"interfaces={} packet-out={}",
new Object[] {sw.getId(), outPorts, pob.build()});
}
messageDamper.write(sw, pob.build());
} catch (IOException e) {
log.error("Failure writing packet out", e);
}
}
项目:iTAP-controller
文件:FloodlightTestCase.java
public static FloodlightContext parseAndAnnotate(FloodlightContext bc, OFMessage m) {
if (OFType.PACKET_IN.equals(m.getType())) {
OFPacketIn pi = (OFPacketIn)m;
Ethernet eth = new Ethernet();
eth.deserialize(pi.getData(), 0, pi.getData().length);
IFloodlightProviderService.bcStore.put(bc,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
}
return bc;
}
项目:iTAP-controller
文件:ControllerTest.java
@Test
public void testHandleMessageWithContext() throws Exception {
IOFSwitch sw = createMock(IOFSwitch.class);
expect(sw.getId()).andReturn(DatapathId.NONE).anyTimes();
IOFMessageListener test1 = createMock(IOFMessageListener.class);
expect(test1.getName()).andReturn("test1").anyTimes();
expect(test1.isCallbackOrderingPrereq((OFType)anyObject(),
(String)anyObject()))
.andReturn(false).anyTimes();
expect(test1.isCallbackOrderingPostreq((OFType)anyObject(),
(String)anyObject()))
.andReturn(false).anyTimes();
FloodlightContext cntx = new FloodlightContext();
expect(test1.receive(same(sw), same(pi) , same(cntx)))
.andReturn(Command.CONTINUE);
IOFMessageListener test2 = createMock(IOFMessageListener.class);
expect(test2.getName()).andReturn("test2").anyTimes();
expect(test2.isCallbackOrderingPrereq((OFType)anyObject(),
(String)anyObject()))
.andReturn(false).anyTimes();
expect(test2.isCallbackOrderingPostreq((OFType)anyObject(),
(String)anyObject()))
.andReturn(false).anyTimes();
// test2 will not receive any message!
replay(test1, test2, sw);
controller.addOFMessageListener(OFType.PACKET_IN, test1);
controller.addOFMessageListener(OFType.ERROR, test2);
controller.handleMessage(sw, pi, cntx);
verify(test1, test2, sw);
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
assertArrayEquals(testPacket.serialize(), eth.serialize());
}