public static OFFlowModify toFlowModify(OFFlowMod fm) { OFVersion version = fm.getVersion(); OFFlowModify.Builder b = OFFactories.getFactory(version).buildFlowModify(); if (b.getVersion().compareTo(OFVersion.OF_10) == 0) { return b.setActions(fm.getActions()) .setBufferId(fm.getBufferId()) .setCookie(fm.getCookie()) // cookie-mask not supported .setFlags(fm.getFlags()) .setHardTimeout(fm.getHardTimeout()) .setIdleTimeout(fm.getIdleTimeout()) // instructions not supported .setMatch(fm.getMatch()) // out-group not supported .setOutPort(fm.getOutPort()) .setPriority(fm.getPriority()) // table-id not supported .setXid(fm.getXid()) .build(); } else { return b.setActions(fm.getActions()) .setBufferId(fm.getBufferId()) .setCookie(fm.getCookie()) .setCookieMask(fm.getCookieMask()) // added in OF1.1 .setFlags(fm.getFlags()) .setHardTimeout(fm.getHardTimeout()) .setIdleTimeout(fm.getIdleTimeout()) .setInstructions(fm.getInstructions()) // added in OF1.1 .setMatch(fm.getMatch()) .setOutGroup(fm.getOutGroup()) // added in OF1.1 .setOutPort(fm.getOutPort()) .setPriority(fm.getPriority()) .setTableId(fm.getTableId()) .setXid(fm.getXid()) .build(); } }
/** * Test FlowObject is correctly converted to message and is sent to a switch. */ @SuppressWarnings("unchecked") @Test public void testAddFlow() { Dpid dpid = new Dpid(DPID_TO_VERIFY); // instantiate required objects FlowEntry flowEntry1 = new FlowEntry(DPID_TO_VERIFY, 1, 11, null, null, 0, 0, Operator.ADD); beginInitMock(); OFFlowModify fm = createMock(OFFlowModify.class); OFFlowModify.Builder bld = createMock(OFFlowModify.Builder.class); expect(bld.setIdleTimeout(anyInt())).andReturn(bld); expect(bld.setHardTimeout(anyInt())).andReturn(bld); expect(bld.setPriority(anyShort())).andReturn(bld); expect(bld.setBufferId(OFBufferId.NO_BUFFER)).andReturn(bld); expect(bld.setCookie(U64.of(anyLong()))).andReturn(bld); expect(bld.setMatch(anyObject(Match.class))).andReturn(bld); expect(bld.setActions((List<OFAction>) anyObject())).andReturn(bld); expect(bld.setOutPort(OFPort.of(anyInt()))).andReturn(bld).atLeastOnce(); expect(bld.build()).andReturn(fm); expect(fm.getXid()).andReturn(XID_TO_VERIFY).anyTimes(); expect(fm.getType()).andReturn(OFType.FLOW_MOD).anyTimes(); IOFSwitch sw = createConnectedSwitchMock(DPID_TO_VERIFY); try { sw.write(anyObject(OFMessage.class), eq((FloodlightContext) null)); expectLastCall().once(); } catch (IOException e1) { fail("Failed in IOFWrite#write()"); } replay(bld, fm); replay(sw); endInitMock(); initPusher(1); pusher.pushFlowEntry(dpid, flowEntry1); try { Thread.sleep(1000); } catch (InterruptedException e) { fail("Failed to sleep"); } verify(sw); verifyAll(); pusher.stop(); }