1 package org.openkilda.floodlight.switchmanager;
3 import static java.util.Collections.singletonList;
4 import static org.easymock.EasyMock.capture;
5 import static org.easymock.EasyMock.createMock;
6 import static org.easymock.EasyMock.expect;
7 import static org.junit.Assert.assertEquals;
10 import net.floodlightcontroller.core.IOFSwitch;
11 import net.floodlightcontroller.core.internal.IOFSwitchService;
12 import net.floodlightcontroller.core.module.FloodlightModuleContext;
13 import net.floodlightcontroller.core.module.FloodlightModuleException;
14 import org.easymock.Capture;
15 import org.easymock.EasyMock;
16 import org.junit.Before;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
20 import org.projectfloodlight.openflow.protocol.OFFactory;
21 import org.projectfloodlight.openflow.protocol.OFFlowMod;
22 import org.projectfloodlight.openflow.protocol.match.MatchField;
23 import org.projectfloodlight.openflow.types.DatapathId;
24 import org.projectfloodlight.openflow.types.OFPort;
25 import org.projectfloodlight.openflow.types.OFVlanVidMatch;
26 import org.projectfloodlight.openflow.types.U64;
29 private static final FloodlightModuleContext context =
new FloodlightModuleContext();
30 private static IOFSwitchService switchService = createMock(IOFSwitchService.class);
33 private final DatapathId switchDpId = DatapathId.of(0xdeadbeaf00000001L);
34 private final long commonFlowCookie = 0x77AA55AA0001L;
35 private IOFSwitch ofSwitch = createMock(IOFSwitch.class);
41 context.addService(IOFSwitchService.class, switchService);
45 public void setUp() throws FloodlightModuleException {
46 EasyMock.reset(switchService);
49 switchManager.
init(context);
54 Capture<OFFlowMod> capture = prepareForInstallFlowOperation();
56 String flowId =
"test-transit-flow-rule";
59 int transitVlanId = 512;
60 switchManager.
installTransitFlow(switchDpId, flowId, commonFlowCookie, inputPort, outputPort, transitVlanId);
63 OFFlowMod expected = referenceOfFactory.buildFlowAdd()
65 .setPriority(DEFAULT_RULE_PRIORITY)
66 .setMatch(referenceOfFactory.buildMatch()
67 .setExact(MatchField.IN_PORT, OFPort.of(inputPort))
68 .setMasked(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlanId), OFVlanVidMatch.ofRawVid(
71 .setInstructions(singletonList(
72 referenceOfFactory.instructions().applyActions(singletonList(
73 referenceOfFactory.actions().buildOutput()
74 .setMaxLen(0xFFFFFFFF)
75 .setPort(OFPort.of(outputPort))
81 assertEquals(expected, capture.getValue());
84 private Capture<OFFlowMod> prepareForInstallFlowOperation() {
85 Capture<OFFlowMod> capture = EasyMock.newCapture();
87 expect(switchService.getSwitch(switchDpId)).andStubReturn(ofSwitch);
88 expect(ofSwitch.getOFFactory()).andStubReturn(ofFactory);
89 expect(ofSwitch.write(capture(capture))).andReturn(
true);
90 EasyMock.expectLastCall();
92 EasyMock.replay(switchService);
93 EasyMock.replay(ofSwitch);
void init(FloodlightModuleContext context)
void installTransitFlow()
static final int DEFAULT_RULE_PRIORITY
long installTransitFlow(final DatapathId dpid, final String flowId, final Long cookie, final int inputPort, final int outputPort, final int transitVlanId)
static final long FLOW_COOKIE_MASK