Skip to content
Snippets Groups Projects
Commit 00dc75c3 authored by Ryan Izard's avatar Ryan Izard
Browse files

Fixed OFMessageDamper unit tests and removed context from within...

Fixed OFMessageDamper unit tests and removed context from within OFMessageDamper (not used with a switch write anymore).
parent c4c8bfb3
No related branches found
No related tags found
No related merge requests found
...@@ -102,7 +102,6 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -102,7 +102,6 @@ public class LoadBalancer implements IFloodlightModule,
protected IRestApiService restApiService; protected IRestApiService restApiService;
protected IDebugCounterService debugCounterService; protected IDebugCounterService debugCounterService;
protected OFMessageDamper messageDamper;
protected IDeviceService deviceManagerService; protected IDeviceService deviceManagerService;
protected IRoutingService routingEngineService; protected IRoutingService routingEngineService;
protected ITopologyService topologyService; protected ITopologyService topologyService;
...@@ -235,7 +234,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -235,7 +234,7 @@ public class LoadBalancer implements IFloodlightModule,
pushBidirectionalVipRoutes(sw, pi, cntx, client, member); pushBidirectionalVipRoutes(sw, pi, cntx, client, member);
// packet out based on table rule // packet out based on table rule
pushPacket(pkt, sw, pi.getBufferId(), pi.getInPort(), OFPort.TABLE, pushPacket(pkt, sw, pi.getBufferId(), pi.getVersion() == OFVersion.OF_10 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT), OFPort.TABLE,
cntx, true); cntx, true);
return Command.STOP; return Command.STOP;
...@@ -291,7 +290,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -291,7 +290,7 @@ public class LoadBalancer implements IFloodlightModule,
arpRequest.getSenderProtocolAddress())); arpRequest.getSenderProtocolAddress()));
// push ARP reply out // push ARP reply out
pushPacket(arpReply, sw, OFBufferId.NO_BUFFER, OFPort.ZERO, pi.getMatch().get(MatchField.IN_PORT), cntx, true); pushPacket(arpReply, sw, OFBufferId.NO_BUFFER, OFPort.ANY, pi.getMatch().get(MatchField.IN_PORT), cntx, true);
log.debug("proxy ARP reply pushed as {}", IPv4.fromIPv4Address(vips.get(vipId).address)); log.debug("proxy ARP reply pushed as {}", IPv4.fromIPv4Address(vips.get(vipId).address));
return; return;
...@@ -324,7 +323,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -324,7 +323,7 @@ public class LoadBalancer implements IFloodlightModule,
// set actions // set actions
List<OFAction> actions = new ArrayList<OFAction>(); List<OFAction> actions = new ArrayList<OFAction>();
actions.add(sw.getOFFactory().actions().buildOutput().setPort(outPort).build()); actions.add(sw.getOFFactory().actions().buildOutput().setPort(outPort).setMaxLen(Integer.MAX_VALUE).build());
pob.setActions(actions); pob.setActions(actions);
...@@ -345,12 +344,8 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -345,12 +344,8 @@ public class LoadBalancer implements IFloodlightModule,
pob.setData(packetData); pob.setData(packetData);
} }
try { //TODO @Ryan debugCounterService.updatePktOutFMCounterStoreLocal(sw, pob.build());
//TODO @Ryan debugCounterService.updatePktOutFMCounterStoreLocal(sw, pob.build()); sw.write(pob.build());
messageDamper.write(sw, pob.build(), cntx, flush);
} catch (IOException e) {
log.error("Failure writing packet out", e);
}
} }
/** /**
...@@ -470,11 +465,11 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -470,11 +465,11 @@ public class LoadBalancer implements IFloodlightModule,
// out: match dest client (ip, port), rewrite src from member ip/port to vip ip/port, forward // out: match dest client (ip, port), rewrite src from member ip/port to vip ip/port, forward
if (routeIn != null) { if (routeIn != null) {
pushStaticVipRoute(true, routeIn, client, member, sw.getId()); pushStaticVipRoute(true, routeIn, client, member, sw);
} }
if (routeOut != null) { if (routeOut != null) {
pushStaticVipRoute(false, routeOut, client, member, sw.getId()); pushStaticVipRoute(false, routeOut, client, member, sw);
} }
} }
...@@ -497,7 +492,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -497,7 +492,7 @@ public class LoadBalancer implements IFloodlightModule,
* @param LBMember member * @param LBMember member
* @param long pinSwitch * @param long pinSwitch
*/ */
public void pushStaticVipRoute(boolean inBound, Route route, IPClient client, LBMember member, DatapathId pinSwitch) { public void pushStaticVipRoute(boolean inBound, Route route, IPClient client, LBMember member, IOFSwitch pinSwitch) {
List<NodePortTuple> path = route.getPath(); List<NodePortTuple> path = route.getPath();
if (path.size() > 0) { if (path.size() > 0) {
for (int i = 0; i < path.size(); i+=2) { for (int i = 0; i < path.size(); i+=2) {
...@@ -508,7 +503,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -508,7 +503,7 @@ public class LoadBalancer implements IFloodlightModule,
String matchString = null; String matchString = null;
String actionString = null; String actionString = null;
OFFlowMod.Builder fmb = switchService.getSwitch(pinSwitch).getOFFactory().buildFlowAdd(); OFFlowMod.Builder fmb = pinSwitch.getOFFactory().buildFlowAdd();
fmb.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT); fmb.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT);
fmb.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT); fmb.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT);
...@@ -526,7 +521,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -526,7 +521,7 @@ public class LoadBalancer implements IFloodlightModule,
+ MatchUtils.STR_DL_TYPE + "="+LB_ETHER_TYPE+"," + MatchUtils.STR_DL_TYPE + "="+LB_ETHER_TYPE+","
+ MatchUtils.STR_IN_PORT + "="+path.get(i).getPortId().toString(); + MatchUtils.STR_IN_PORT + "="+path.get(i).getPortId().toString();
if (sw == pinSwitch) { if (sw.equals(pinSwitch.getId())) {
actionString = "set-dst-ip="+IPv4.fromIPv4Address(member.address)+"," actionString = "set-dst-ip="+IPv4.fromIPv4Address(member.address)+","
+ "set-dst-mac="+member.macString+"," + "set-dst-mac="+member.macString+","
+ "output="+path.get(i+1).getPortId(); + "output="+path.get(i+1).getPortId();
...@@ -543,7 +538,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -543,7 +538,7 @@ public class LoadBalancer implements IFloodlightModule,
+ MatchUtils.STR_DL_TYPE + "="+LB_ETHER_TYPE+"," + MatchUtils.STR_DL_TYPE + "="+LB_ETHER_TYPE+","
+ MatchUtils.STR_IN_PORT + "="+path.get(i).getPortId().toString(); + MatchUtils.STR_IN_PORT + "="+path.get(i).getPortId().toString();
if (sw == pinSwitch) { if (sw.equals(pinSwitch.getId())) {
actionString = ActionUtils.STR_NW_SRC_SET + "="+IPv4.fromIPv4Address(vips.get(member.vipId).address)+"," actionString = ActionUtils.STR_NW_SRC_SET + "="+IPv4.fromIPv4Address(vips.get(member.vipId).address)+","
+ ActionUtils.STR_DL_SRC_SET + "="+vips.get(member.vipId).proxyMac.toString()+"," + ActionUtils.STR_DL_SRC_SET + "="+vips.get(member.vipId).proxyMac.toString()+","
+ ActionUtils.STR_OUTPUT + "="+path.get(i+1).getPortId(); + ActionUtils.STR_OUTPUT + "="+path.get(i+1).getPortId();
...@@ -559,7 +554,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -559,7 +554,7 @@ public class LoadBalancer implements IFloodlightModule,
Match match = null; Match match = null;
try { try {
match = MatchUtils.fromString(matchString, switchService.getSwitch(sw).getOFFactory().getVersion()); match = MatchUtils.fromString(matchString, pinSwitch.getOFFactory().getVersion());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
log.debug("ignoring flow entry {} on switch {} with illegal OFMatch() key: " + matchString, entryName, swString); log.debug("ignoring flow entry {} on switch {} with illegal OFMatch() key: " + matchString, entryName, swString);
} }
...@@ -797,10 +792,6 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -797,10 +792,6 @@ public class LoadBalancer implements IFloodlightModule,
sfpService = context.getServiceImpl(IStaticFlowEntryPusherService.class); sfpService = context.getServiceImpl(IStaticFlowEntryPusherService.class);
switchService = context.getServiceImpl(IOFSwitchService.class); switchService = context.getServiceImpl(IOFSwitchService.class);
messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY,
EnumSet.of(OFType.FLOW_MOD),
OFMESSAGE_DAMPER_TIMEOUT);
vips = new HashMap<String, LBVip>(); vips = new HashMap<String, LBVip>();
pools = new HashMap<String, LBPool>(); pools = new HashMap<String, LBPool>();
members = new HashMap<String, LBMember>(); members = new HashMap<String, LBMember>();
......
...@@ -20,9 +20,7 @@ import java.io.IOException; ...@@ -20,9 +20,7 @@ import java.io.IOException;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Set; import java.util.Set;
import net.floodlightcontroller.core.FloodlightContext;
import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.LogicalOFMessageCategory;
import org.projectfloodlight.openflow.protocol.OFMessage; import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFType; import org.projectfloodlight.openflow.protocol.OFType;
...@@ -108,31 +106,29 @@ public class OFMessageDamper { ...@@ -108,31 +106,29 @@ public class OFMessageDamper {
} }
/** /**
* write the messag to the switch according to our dampening settings * write the message to the switch according to our dampening settings
* @param sw * @param sw
* @param msg * @param msg
* @param cntx
* @return true if the message was written to the switch, false if * @return true if the message was written to the switch, false if
* the message was dampened. * the message was dampened.
* @throws IOException * @throws IOException
*/ */
public boolean write(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) throws IOException { public boolean write(IOFSwitch sw, OFMessage msg) throws IOException {
return write(sw, msg, cntx, false); return write(sw, msg, false);
} }
/** /**
* write the messag to the switch according to our dampening settings * write the message to the switch according to our dampening settings
* @param sw * @param sw
* @param msg * @param msg
* @param cntx * @param flush true to flush the packet immediately
* @param flush true to flush the packet immidiately
* @return true if the message was written to the switch, false if * @return true if the message was written to the switch, false if
* the message was dampened. * the message was dampened.
* @throws IOException * @throws IOException
*/ */
public boolean write(IOFSwitch sw, OFMessage msg, FloodlightContext cntx, boolean flush) throws IOException { public boolean write(IOFSwitch sw, OFMessage msg, boolean flush) throws IOException {
if (! msgTypesToCache.contains(msg.getType())) { if (!msgTypesToCache.contains(msg.getType())) {
sw.write(msg, LogicalOFMessageCategory.MAIN); sw.write(msg);
if (flush) { if (flush) {
sw.flush(); sw.flush();
} }
......
...@@ -115,12 +115,15 @@ public class LoadBalancerTest extends FloodlightTestCase { ...@@ -115,12 +115,15 @@ public class LoadBalancerTest extends FloodlightTestCase {
protected LBVip vip1, vip2; protected LBVip vip1, vip2;
protected LBPool pool1, pool2, pool3; protected LBPool pool1, pool2, pool3;
protected LBMember member1, member2, member3, member4; protected LBMember member1, member2, member3, member4;
private OFFactory factory;
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
factory = OFFactories.getFactory(OFVersion.OF_13);
lb = new LoadBalancer(); lb = new LoadBalancer();
cntx = new FloodlightContext(); cntx = new FloodlightContext();
...@@ -155,7 +158,7 @@ public class LoadBalancerTest extends FloodlightTestCase { ...@@ -155,7 +158,7 @@ public class LoadBalancerTest extends FloodlightTestCase {
fmc.addService(IOFSwitchService.class, getMockSwitchService()); fmc.addService(IOFSwitchService.class, getMockSwitchService());
lb.init(fmc); lb.init(fmc);
getMockFloodlightProvider().init(fmc); //getMockFloodlightProvider().init(fmc);
entityClassifier.init(fmc); entityClassifier.init(fmc);
frm.init(fmc); frm.init(fmc);
tps.init(fmc); tps.init(fmc);
...@@ -170,7 +173,7 @@ public class LoadBalancerTest extends FloodlightTestCase { ...@@ -170,7 +173,7 @@ public class LoadBalancerTest extends FloodlightTestCase {
replay(topology); replay(topology);
lb.startUp(fmc); lb.startUp(fmc);
getMockFloodlightProvider().startUp(fmc); //getMockFloodlightProvider().startUp(fmc);
entityClassifier.startUp(fmc); entityClassifier.startUp(fmc);
frm.startUp(fmc); frm.startUp(fmc);
tps.startUp(fmc); tps.startUp(fmc);
...@@ -427,7 +430,6 @@ public class LoadBalancerTest extends FloodlightTestCase { ...@@ -427,7 +430,6 @@ public class LoadBalancerTest extends FloodlightTestCase {
testCreateMember(); testCreateMember();
IOFSwitch sw1; IOFSwitch sw1;
OFFactory factory;
IPacket arpRequest1, arpReply1, icmpPacket1, icmpPacket2; IPacket arpRequest1, arpReply1, icmpPacket1, icmpPacket2;
...@@ -443,19 +445,14 @@ public class LoadBalancerTest extends FloodlightTestCase { ...@@ -443,19 +445,14 @@ public class LoadBalancerTest extends FloodlightTestCase {
Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL); Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);
sw1 = EasyMock.createNiceMock(IOFSwitch.class); sw1 = EasyMock.createNiceMock(IOFSwitch.class);
factory = EasyMock.createNiceMock(OFFactory.class);
expect(sw1.getId()).andReturn(DatapathId.of(1L)).anyTimes(); expect(sw1.getId()).andReturn(DatapathId.of(1L)).anyTimes();
expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes(); expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
expect(sw1.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes(); expect(sw1.getOFFactory()).andReturn(factory).anyTimes();
expect(factory.buildFlowAdd()).andReturn(OFFactories.getFactory(OFVersion.OF_13).buildFlowAdd()).anyTimes();
expect(factory.buildFlowDelete()).andReturn(OFFactories.getFactory(OFVersion.OF_13).buildFlowDelete()).anyTimes();
expect(factory.buildFlowModify()).andReturn(OFFactories.getFactory(OFVersion.OF_13).buildFlowModify()).anyTimes();
sw1.write(capture(wc1)); sw1.write(capture(wc1));
expectLastCall().anyTimes(); expectLastCall().anyTimes();
sw1.flush(); sw1.flush();
expectLastCall().anyTimes(); expectLastCall().anyTimes();
replay(factory);
replay(sw1); replay(sw1);
sfp.switchAdded(DatapathId.of(1L)); sfp.switchAdded(DatapathId.of(1L));
...@@ -482,20 +479,6 @@ public class LoadBalancerTest extends FloodlightTestCase { ...@@ -482,20 +479,6 @@ public class LoadBalancerTest extends FloodlightTestCase {
expect(topology.isAttachmentPointPort(DatapathId.of(1L), OFPort.of(3))).andReturn(true).anyTimes(); expect(topology.isAttachmentPointPort(DatapathId.of(1L), OFPort.of(3))).andReturn(true).anyTimes();
expect(topology.isAttachmentPointPort(DatapathId.of(1L), OFPort.of(4))).andReturn(true).anyTimes(); expect(topology.isAttachmentPointPort(DatapathId.of(1L), OFPort.of(4))).andReturn(true).anyTimes();
replay(topology); replay(topology);
reset(sw1);
reset(factory);
expect(sw1.getId()).andReturn(DatapathId.of(1L)).anyTimes();
expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
expect(sw1.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
sw1.write(capture(wc1));
expect(factory.buildFlowAdd()).andReturn(OFFactories.getFactory(OFVersion.OF_13).buildFlowAdd()).anyTimes();
expect(factory.buildFlowDelete()).andReturn(OFFactories.getFactory(OFVersion.OF_13).buildFlowDelete()).anyTimes();
expect(factory.buildFlowModify()).andReturn(OFFactories.getFactory(OFVersion.OF_13).buildFlowModify()).anyTimes();
replay(factory);
replay(sw1);
// Build arp packets // Build arp packets
arpRequest1 = new Ethernet() arpRequest1 = new Ethernet()
...@@ -518,8 +501,8 @@ public class LoadBalancerTest extends FloodlightTestCase { ...@@ -518,8 +501,8 @@ public class LoadBalancerTest extends FloodlightTestCase {
arpRequest1Serialized = arpRequest1.serialize(); arpRequest1Serialized = arpRequest1.serialize();
arpRequestPacketIn1 = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn() arpRequestPacketIn1 = factory.buildPacketIn()
.setMatch(OFFactories.getFactory(OFVersion.OF_13).buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build()) .setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
.setBufferId(OFBufferId.NO_BUFFER) .setBufferId(OFBufferId.NO_BUFFER)
.setData(arpRequest1Serialized) .setData(arpRequest1Serialized)
.setReason(OFPacketInReason.NO_MATCH) .setReason(OFPacketInReason.NO_MATCH)
...@@ -551,12 +534,13 @@ public class LoadBalancerTest extends FloodlightTestCase { ...@@ -551,12 +534,13 @@ public class LoadBalancerTest extends FloodlightTestCase {
arpReply1Serialized = arpReply1.serialize(); arpReply1Serialized = arpReply1.serialize();
List<OFAction> poactions = new ArrayList<OFAction>(); List<OFAction> poactions = new ArrayList<OFAction>();
poactions.add(OFFactories.getFactory(OFVersion.OF_13).actions().output(arpRequestPacketIn1.getMatch().get(MatchField.IN_PORT), (short) 0xffff)); poactions.add(factory.actions().output(arpRequestPacketIn1.getMatch().get(MatchField.IN_PORT), Integer.MAX_VALUE));
arpReplyPacketOut1 = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut() arpReplyPacketOut1 = factory.buildPacketOut()
.setBufferId(OFBufferId.NO_BUFFER) .setBufferId(OFBufferId.NO_BUFFER)
.setInPort(OFPort.ANY) .setInPort(OFPort.ANY)
.setActions(poactions) .setActions(poactions)
.setData(arpReply1Serialized) .setData(arpReply1Serialized)
.setXid(3)
.build(); .build();
sw1.write(arpReplyPacketOut1); sw1.write(arpReplyPacketOut1);
......
...@@ -25,7 +25,6 @@ import java.util.List; ...@@ -25,7 +25,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import net.floodlightcontroller.core.FloodlightContext;
import net.floodlightcontroller.core.IOFConnection; import net.floodlightcontroller.core.IOFConnection;
import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.LogicalOFMessageCategory; import net.floodlightcontroller.core.LogicalOFMessageCategory;
...@@ -59,7 +58,6 @@ import com.google.common.util.concurrent.ListenableFuture; ...@@ -59,7 +58,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/ */
public class OFMessageDamperMockSwitch implements IOFSwitch { public class OFMessageDamperMockSwitch implements IOFSwitch {
OFMessage writtenMessage; OFMessage writtenMessage;
FloodlightContext writtenContext;
public OFMessageDamperMockSwitch() { public OFMessageDamperMockSwitch() {
reset(); reset();
...@@ -68,19 +66,15 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { ...@@ -68,19 +66,15 @@ public class OFMessageDamperMockSwitch implements IOFSwitch {
/* reset this mock. I.e., clear the stored message previously written */ /* reset this mock. I.e., clear the stored message previously written */
public void reset() { public void reset() {
writtenMessage = null; writtenMessage = null;
writtenContext = null;
} }
/* assert that a message was written to this switch and that the /* assert that a message was written to this switch and that the
* written message and context matches the expected values * written message and context matches the expected values
* @param expected * @param expected
* @param expectedContext
*/ */
public void assertMessageWasWritten(OFMessage expected, public void assertMessageWasWritten(OFMessage expected) {
FloodlightContext expectedContext) {
assertNotNull("No OFMessage was written", writtenMessage); assertNotNull("No OFMessage was written", writtenMessage);
assertEquals(expected, writtenMessage); assertEquals(expected, writtenMessage);
assertEquals(expectedContext, writtenContext);
} }
/* /*
...@@ -89,8 +83,6 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { ...@@ -89,8 +83,6 @@ public class OFMessageDamperMockSwitch implements IOFSwitch {
public void assertNoMessageWritten() { public void assertNoMessageWritten() {
assertNull("OFMessage was written but didn't expect one", assertNull("OFMessage was written but didn't expect one",
writtenMessage); writtenMessage);
assertNull("There was a context but didn't expect one",
writtenContext);
} }
/* /*
...@@ -208,14 +200,13 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { ...@@ -208,14 +200,13 @@ public class OFMessageDamperMockSwitch implements IOFSwitch {
@Override @Override
public void write(OFMessage m) { public void write(OFMessage m) {
// TODO Auto-generated method stub writtenMessage = m;
// TODO Auto-generated method stub
} }
@Override @Override
public void write(Iterable<OFMessage> msglist) { public void write(Iterable<OFMessage> msglist) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package net.floodlightcontroller.util; package net.floodlightcontroller.util;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import net.floodlightcontroller.core.FloodlightContext;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -35,7 +34,6 @@ import java.util.EnumSet; ...@@ -35,7 +34,6 @@ import java.util.EnumSet;
public class OFMessageDamperTest { public class OFMessageDamperTest {
OFFactory factory; OFFactory factory;
OFMessageDamper damper; OFMessageDamper damper;
FloodlightContext cntx;
OFMessageDamperMockSwitch sw1; OFMessageDamperMockSwitch sw1;
OFMessageDamperMockSwitch sw2; OFMessageDamperMockSwitch sw2;
...@@ -51,7 +49,6 @@ public class OFMessageDamperTest { ...@@ -51,7 +49,6 @@ public class OFMessageDamperTest {
@Before @Before
public void setUp() throws IOException { public void setUp() throws IOException {
factory = OFFactories.getFactory(OFVersion.OF_13); factory = OFFactories.getFactory(OFVersion.OF_13);
cntx = new FloodlightContext();
sw1 = new OFMessageDamperMockSwitch(); sw1 = new OFMessageDamperMockSwitch();
sw2 = new OFMessageDamperMockSwitch(); sw2 = new OFMessageDamperMockSwitch();
...@@ -66,16 +63,15 @@ public class OFMessageDamperTest { ...@@ -66,16 +63,15 @@ public class OFMessageDamperTest {
protected void doWrite(boolean expectWrite, protected void doWrite(boolean expectWrite,
OFMessageDamperMockSwitch sw, OFMessageDamperMockSwitch sw,
OFMessage msg, OFMessage msg) throws IOException {
FloodlightContext cntx) throws IOException {
boolean result; boolean result;
sw.reset(); sw.reset();
result = damper.write(sw, msg, cntx); result = damper.write(sw, msg);
if (expectWrite) { if (expectWrite) {
assertEquals(true, result); assertEquals(true, result);
sw.assertMessageWasWritten(msg, cntx); sw.assertMessageWasWritten(msg);
} else { } else {
assertEquals(false, result); assertEquals(false, result);
sw.assertNoMessageWritten(); sw.assertNoMessageWritten();
...@@ -94,26 +90,26 @@ public class OFMessageDamperTest { ...@@ -94,26 +90,26 @@ public class OFMessageDamperTest {
// echo requests should be dampened // echo requests should be dampened
doWrite(true, sw1, echoRequst1, cntx); doWrite(true, sw1, echoRequst1);
doWrite(false, sw1, echoRequst1, cntx); doWrite(false, sw1, echoRequst1);
doWrite(false, sw1, echoRequst1Clone, cntx); doWrite(false, sw1, echoRequst1Clone);
doWrite(true, sw1, echoRequst2, cntx); doWrite(true, sw1, echoRequst2);
doWrite(false, sw1, echoRequst2, cntx); doWrite(false, sw1, echoRequst2);
// we don't dampen hellos. All should succeed // we don't dampen hellos. All should succeed
doWrite(true, sw1, hello1, cntx); doWrite(true, sw1, hello1);
doWrite(true, sw1, hello1, cntx); doWrite(true, sw1, hello1);
doWrite(true, sw1, hello1, cntx); doWrite(true, sw1, hello1);
// echo request should also be dampened on sw2 // echo request should also be dampened on sw2
doWrite(true, sw2, echoRequst1, cntx); doWrite(true, sw2, echoRequst1);
doWrite(false, sw2, echoRequst1, cntx); doWrite(false, sw2, echoRequst1);
doWrite(true, sw2, echoRequst2, cntx); doWrite(true, sw2, echoRequst2);
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
doWrite(true, sw1, echoRequst1, cntx); doWrite(true, sw1, echoRequst1);
doWrite(true, sw2, echoRequst1, cntx); doWrite(true, sw2, echoRequst1);
} }
...@@ -129,31 +125,31 @@ public class OFMessageDamperTest { ...@@ -129,31 +125,31 @@ public class OFMessageDamperTest {
// echo requests should be dampened // echo requests should be dampened
doWrite(true, sw1, echoRequst1, cntx); doWrite(true, sw1, echoRequst1);
doWrite(false, sw1, echoRequst1, cntx); doWrite(false, sw1, echoRequst1);
doWrite(false, sw1, echoRequst1Clone, cntx); doWrite(false, sw1, echoRequst1Clone);
doWrite(true, sw1, echoRequst2, cntx); doWrite(true, sw1, echoRequst2);
doWrite(false, sw1, echoRequst2, cntx); doWrite(false, sw1, echoRequst2);
// hello should be dampened as well // hello should be dampened as well
doWrite(true, sw1, hello1, cntx); doWrite(true, sw1, hello1);
doWrite(false, sw1, hello1, cntx); doWrite(false, sw1, hello1);
doWrite(false, sw1, hello1, cntx); doWrite(false, sw1, hello1);
doWrite(true, sw1, hello2, cntx); doWrite(true, sw1, hello2);
doWrite(false, sw1, hello2, cntx); doWrite(false, sw1, hello2);
doWrite(false, sw1, hello2, cntx); doWrite(false, sw1, hello2);
// echo request should also be dampened on sw2 // echo request should also be dampened on sw2
doWrite(true, sw2, echoRequst1, cntx); doWrite(true, sw2, echoRequst1);
doWrite(false, sw2, echoRequst1, cntx); doWrite(false, sw2, echoRequst1);
doWrite(true, sw2, echoRequst2, cntx); doWrite(true, sw2, echoRequst2);
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
doWrite(true, sw1, echoRequst1, cntx); doWrite(true, sw1, echoRequst1);
doWrite(true, sw2, echoRequst1, cntx); doWrite(true, sw2, echoRequst1);
doWrite(true, sw1, hello1, cntx); doWrite(true, sw1, hello1);
doWrite(true, sw1, hello2, cntx); doWrite(true, sw1, hello2);
} }
} }
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