private static void salToOFFlowCommand(Flow flow, FlowModInputBuilder flowMod) { if (flow instanceof AddFlowInput || flow instanceof UpdatedFlow) { flowMod.setCommand(FlowModCommand.OFPFCADD); } else if (flow instanceof RemoveFlowInput) { if (MoreObjects.firstNonNull(flow.isStrict(), Boolean.FALSE)) { flowMod.setCommand(FlowModCommand.OFPFCDELETESTRICT); } else { flowMod.setCommand(FlowModCommand.OFPFCDELETE); } } }
@Override public void inject(final FlowModFlags value, final FlowModInputBuilder target) { target.setFlags(value); } });
@Override public void inject(final FlowModFlagsV10 value, final FlowModInputBuilder target) { target.setFlagsV10(value); } });
@Override public FlowModInput deserialize(ByteBuf rawMessage) { FlowModInputBuilder builder = new FlowModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); builder.setCookie(new BigInteger(1, cookie)); byte[] cookie_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie_mask); builder.setCookieMask(new BigInteger(1, cookie_mask)); builder.setTableId(new TableId((long) rawMessage.readUnsignedByte())); builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedByte())); builder.setIdleTimeout(rawMessage.readUnsignedShort()); builder.setHardTimeout(rawMessage.readUnsignedShort()); builder.setPriority(rawMessage.readUnsignedShort()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setOutPort(new PortNumber(rawMessage.readUnsignedInt())); builder.setOutGroup(rawMessage.readUnsignedInt()); builder.setFlags(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort())); rawMessage.skipBytes(PADDING); OFDeserializer<Match> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); builder.setMatch(matchDeserializer.deserialize(rawMessage)); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry); builder.setInstruction(instructions); return builder.build(); }
@Override public FlowModInput deserialize(ByteBuf rawMessage) { FlowModInputBuilder builder = new FlowModInputBuilder(); builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class)); builder.setMatchV10(matchDeserializer.deserialize(rawMessage)); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); builder.setCookie(new BigInteger(1, cookie)); builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedShort())); builder.setIdleTimeout(rawMessage.readUnsignedShort()); builder.setHardTimeout(rawMessage.readUnsignedShort()); builder.setPriority(rawMessage.readUnsignedShort()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setOutPort(new PortNumber((long) rawMessage.readUnsignedShort())); builder.setFlagsV10(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort())); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry); builder.setAction(actions); return builder.build(); }
private FlowModInputBuilder toFlowModInput(Flow flow, short version, BigInteger datapathid) { FlowModInputBuilder flowMod = new FlowModInputBuilder(); salToOFFlowCookie(flow, flowMod); salToOFFlowCookieMask(flow, flowMod); salToOFFlowTableId(flow, flowMod); salToOFFlowCommand(flow, flowMod); salToOFFlowIdleTimeout(flow, flowMod); salToOFFlowHardTimeout(flow, flowMod); salToOFFlowPriority(flow, flowMod); salToOFFlowBufferId(flow, flowMod); salToOFFlowOutPort(flow, flowMod); salToOFFlowOutGroup(flow, flowMod); // convert and inject flowFlags FlowFlagReactor.getInstance().convert(flow.getFlags(), version, flowMod, getConvertorExecutor()); // convert and inject match MatchReactor.getInstance().convert(flow.getMatch(), version, flowMod, getConvertorExecutor()); if (flow.getInstructions() != null) { flowMod.setInstruction(toInstructions(flow, version, datapathid)); flowMod.setAction(getActions(version, datapathid, flow)); } flowMod.setVersion(version); return flowMod; }
private static Future<RpcResult<UpdateFlowOutput>> createResultForFlowMod( OFRpcTaskContext taskContext, FlowModInputBuilder flowModInput, SwitchConnectionDistinguisher cookie) { flowModInput.setXid(taskContext.getSession().getNextXid()); return taskContext.getMessageService().flowMod(flowModInput.build(), cookie); }
private static void salToOFFlowBufferId(Flow flow, FlowModInputBuilder flowMod) { if (flow.getBufferId() != null) { flowMod.setBufferId(flow.getBufferId()); } else { flowMod.setBufferId(DEFAULT_BUFFER_ID); } }
private static void salToOFFlowHardTimeout(Flow flow, FlowModInputBuilder flowMod) { if (flow.getHardTimeout() != null) { flowMod.setHardTimeout(flow.getHardTimeout()); } else { flowMod.setHardTimeout(DEFAULT_HARD_TIMEOUT); } }
private static void salToOFFlowCookieMask(Flow flow, FlowModInputBuilder flowMod) { if (flow.getCookieMask() != null) { flowMod.setCookieMask(flow.getCookieMask().getValue()); } else { flowMod.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK); } }