本文整理汇总了Java中org.projectfloodlight.openflow.protocol.OFFlowMod.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java OFFlowMod.Builder方法的具体用法?Java OFFlowMod.Builder怎么用?Java OFFlowMod.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.projectfloodlight.openflow.protocol.OFFlowMod
的用法示例。
在下文中一共展示了OFFlowMod.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildFlowMod
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Create an OFFlowMod that can be passed to StaticEntryPusher.
*
* @param sw switch object
* @param match match for the flow
* @param meter meter for the flow
* @param actions actions for the flow
* @param cookie cookie for the flow
* @param priority priority to set on the flow
* @return {@link OFFlowMod}
*/
private OFFlowMod buildFlowMod(final IOFSwitch sw, final Match match, final OFInstructionMeter meter,
final OFInstructionApplyActions actions, final long cookie, final int priority) {
OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd();
fmb.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT);
fmb.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT);
fmb.setBufferId(OFBufferId.NO_BUFFER);
fmb.setCookie(U64.of(cookie));
fmb.setPriority(priority);
List<OFInstruction> instructions = new ArrayList<>(2);
if (meter != null) { // If no meter then no bandwidth limit
instructions.add(meter);
}
if (actions != null) { // If no instruction then Drops packet
instructions.add(actions);
}
if (match != null) { // If no then match everything
fmb.setMatch(match);
}
return fmb.setInstructions(instructions).build();
}
示例2: createFRESCOFlowMod
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
private OFFlowMod createFRESCOFlowMod(IOFSwitch sw, Match match, List<OFAction> actions, int priority){
OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd();;
fmb.setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT);
fmb.setHardTimeout(FlowModUtils.INFINITE_TIMEOUT);
fmb.setBufferId(OFBufferId.NO_BUFFER);
fmb.setOutPort(OFPort.ANY);
fmb.setCookie(U64.of(0));
fmb.setPriority(U16.t(priority));
fmb.setMatch(match);
fmb.setActions(actions);
return fmb.build();
}
示例3: clearActionsFromString
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Convert the string representation of an OFInstructionClearActions to
* an OFInstructionClearActions. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void clearActionsFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
if (fmb.getVersion().compareTo(OFVersion.OF_11) < 0) {
log.error("Clear Actions Instruction not supported in OpenFlow 1.0");
return;
}
if (inst != null && inst.trim().isEmpty()) { /* Allow the empty string, since this is what specifies clear (i.e. key clear does not have any defined values). */
OFInstructionClearActions i = OFFactories.getFactory(fmb.getVersion()).instructions().clearActions();
log.debug("Appending ClearActions instruction: {}", i);
appendInstruction(fmb, i);
log.debug("All instructions after append: {}", fmb.getInstructions());
} else {
log.error("Got non-empty or null string, but ClearActions should not have any String sub-fields: {}", inst);
}
}
示例4: gotoTableFromString
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Convert the string representation of an OFInstructionGotoTable to
* an OFInstructionGotoTable. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void gotoTableFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
if (inst == null || inst.equals("")) {
return;
}
if (fmb.getVersion().compareTo(OFVersion.OF_11) < 0) {
log.error("Goto Table Instruction not supported in OpenFlow 1.0");
return;
}
OFInstructionGotoTable.Builder ib = OFFactories.getFactory(fmb.getVersion()).instructions().buildGotoTable();
// Get the table ID
if (inst.startsWith("0x")) {
ib.setTableId(TableId.of(Integer.parseInt(inst.replaceFirst("0x", ""), 16)));
} else {
ib.setTableId(TableId.of(Integer.parseInt(inst))).build();
}
log.debug("Appending GotoTable instruction: {}", ib.build());
appendInstruction(fmb, ib.build());
log.debug("All instructions after append: {}", fmb.getInstructions());
}
示例5: appendInstruction
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Adds the instructions to the list of OFInstructions in the OFFlowMod. Any pre-existing
* instruction of the same type is replaced with OFInstruction inst.
* @param fmb, the flow mod to append the instruction to
* @param inst, the instuction to append
*/
public static void appendInstruction(OFFlowMod.Builder fmb, OFInstruction inst) {
List<OFInstruction> newIl = new ArrayList<OFInstruction>();
List<OFInstruction> oldIl = fmb.getInstructions();
if (oldIl != null) { // keep any existing instructions that were added earlier
newIl.addAll(fmb.getInstructions());
}
for (OFInstruction i : newIl) { // remove any duplicates. Only one of each instruction.
if (i.getType() == inst.getType()) {
newIl.remove(i);
}
}
newIl.add(inst);
fmb.setInstructions(newIl);
}
示例6: meterFromString
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Convert the string representation of an OFInstructionMeter to
* an OFInstructionMeter. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void meterFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
if (inst == null || inst.isEmpty()) {
return;
}
if (fmb.getVersion().compareTo(OFVersion.OF_13) < 0) {
log.error("Goto Meter Instruction not supported in OpenFlow 1.0, 1.1, or 1.2");
return;
}
OFInstructionMeter.Builder ib = OFFactories.getFactory(fmb.getVersion()).instructions().buildMeter();
if (inst.startsWith("0x")) {
ib.setMeterId(Long.valueOf(inst.replaceFirst("0x", ""), 16));
} else {
ib.setMeterId(Long.valueOf(inst));
}
log.debug("Appending (Goto)Meter instruction: {}", ib.build());
appendInstruction(fmb, ib.build());
log.debug("All instructions after append: {}", fmb.getInstructions());
}
示例7: experimenterFromString
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Convert the string representation of an OFInstructionExperimenter to
* an OFInstructionExperimenter. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void experimenterFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
/* TODO This is a no-op right now. */
/*
if (inst == null || inst.equals("")) {
return; // TODO @Ryan quietly fail?
}
OFInstructionExperimenter.Builder ib = OFFactories.getFactory(fmb.getVersion()).instructions().buildExperimenter();
String[] keyValue = inst.split("=");
if (keyValue.length != 2) {
throw new IllegalArgumentException("[Key, Value] " + keyValue + " does not have form 'key=value' parsing " + inst);
}
switch (keyValue[0]) {
case STR_SUB_GOTO_METER_METER_ID:
ib.setExperimenter(Long.parseLong(keyValue[1]));
break;
default:
log.error("Invalid String key for OFInstructionExperimenter: {}", keyValue[0]);
}
appendInstruction(fmb, ib.build());
*/
}
示例8: applyActionsFromString
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Convert the string representation of an OFInstructionApplyActions to
* an OFInstructionApplyActions. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void applyActionsFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
if (fmb.getVersion().compareTo(OFVersion.OF_11) < 0) {
log.error("Apply Actions Instruction not supported in OpenFlow 1.0");
return;
}
OFFlowMod.Builder tmpFmb = OFFactories.getFactory(fmb.getVersion()).buildFlowModify();
OFInstructionApplyActions.Builder ib = OFFactories.getFactory(fmb.getVersion()).instructions().buildApplyActions();
ActionUtils.fromString(tmpFmb, inst, log);
ib.setActions(tmpFmb.getActions());
log.debug("Appending ApplyActions instruction: {}", ib.build());
appendInstruction(fmb, ib.build());
log.debug("All instructions after append: {}", fmb.getInstructions()); }
示例9: doDropFlow
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Writes a FlowMod to a switch that inserts a drop flow.
* @param sw The switch to write the FlowMod to.
* @param pi The corresponding OFPacketIn. Used to create the OFMatch structure.
* @param cntx The FloodlightContext that gets passed to the switch.
*/
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
if (log.isTraceEnabled()) {
log.trace("doDropFlow pi={} srcSwitch={}",
new Object[] { pi, sw });
}
if (sw == null) {
log.warn("Switch is null, not installing drop flowmod for PacketIn {}", pi);
return;
}
// Create flow-mod based on packet-in and src-switch
OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowModify();
List<OFAction> actions = new ArrayList<OFAction>(); // no actions = drop
U64 cookie = AppCookie.makeCookie(APP_ID, 0);
fmb.setCookie(cookie)
.setIdleTimeout(ForwardingBase.FLOWMOD_DEFAULT_IDLE_TIMEOUT)
.setHardTimeout(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT)
.setBufferId(OFBufferId.NO_BUFFER)
.setMatch(pi.getMatch())
.setActions(actions);
if (log.isTraceEnabled()) {
log.trace("write drop flow-mod srcSwitch={} match={} " +
"pi={} flow-mod={}",
new Object[] {sw, pi.getMatch(), pi, fmb.build()});
}
sw.write(fmb.build());
return;
}
示例10: initDefaultFlowMod
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Sets defaults for an OFFlowMod used in the StaticFlowEntryPusher
* @param fm The OFFlowMod to set defaults for
* @param entryName The name of the entry. Used to compute the cookie.
*/
public static void initDefaultFlowMod(OFFlowMod.Builder fmb, String entryName) {
fmb.setIdleTimeout(INFINITE_TIMEOUT) // not setting these would also work
.setHardTimeout(INFINITE_TIMEOUT)
.setBufferId(OFBufferId.NO_BUFFER)
.setOutPort(OFPort.ANY)
.setCookie(computeEntryCookie(0, entryName))
.setPriority(Integer.MAX_VALUE)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM));
return;
}
示例11: setActions
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Sets the actions in fmb according to the sw version.
*
* @param fmb the FlowMod Builder that is being built
* @param actions the actions to set
* @param sw the switch that will receive the FlowMod
*/
public static void setActions(OFFlowMod.Builder fmb,
List<OFAction> actions, IOFSwitch sw) {
if (sw.getOFFactory().getVersion().compareTo(OFVersion.OF_11) >= 0) {
// Instructions are used starting in OF 1.1
fmb.setInstructions(Collections.singletonList((OFInstruction) sw
.getOFFactory().instructions().applyActions(actions)));
} else {
// OF 1.0 only supports actions
fmb.setActions(actions);
}
}
示例12: writeActionsFromString
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Convert the string representation of an OFInstructionWriteActions to
* an OFInstructionWriteActions. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void writeActionsFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
if (fmb.getVersion().compareTo(OFVersion.OF_11) < 0) {
log.error("Write Actions Instruction not supported in OpenFlow 1.0");
return;
}
OFFlowMod.Builder tmpFmb = OFFactories.getFactory(fmb.getVersion()).buildFlowModify(); // ActionUtils.fromString() will use setActions(), which should not be used for OF1.3; use temp to avoid overwriting any applyActions data
OFInstructionWriteActions.Builder ib = OFFactories.getFactory(fmb.getVersion()).instructions().buildWriteActions();
ActionUtils.fromString(tmpFmb, inst, log);
ib.setActions(tmpFmb.getActions());
log.debug("Appending WriteActions instruction: {}", ib.build());
appendInstruction(fmb, ib.build());
log.debug("All instructions after append: {}", fmb.getInstructions()); }
示例13: blockHost
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
public static boolean blockHost(IOFSwitchService switchService,
SwitchPort sw_tup, MacAddress host_mac, short hardTimeout, U64 cookie) {
if (sw_tup == null) {
return false;
}
IOFSwitch sw = switchService.getSwitch(sw_tup.getSwitchDPID());
if (sw == null) {
return false;
}
OFPort inputPort = sw_tup.getPort();
log.debug("blockHost sw={} port={} mac={}",
new Object[] { sw, sw_tup.getPort(), host_mac.getLong() });
// Create flow-mod based on packet-in and src-switch
OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd();
Match.Builder mb = sw.getOFFactory().buildMatch();
List<OFAction> actions = new ArrayList<OFAction>(); // Set no action to drop
mb.setExact(MatchField.IN_PORT, inputPort);
if (host_mac.getLong() != -1L) {
mb.setExact(MatchField.ETH_SRC, host_mac);
}
fmb.setCookie(cookie)
.setHardTimeout(hardTimeout)
.setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT)
.setPriority(FLOWMOD_DEFAULT_PRIORITY)
.setBufferId(OFBufferId.NO_BUFFER)
.setMatch(mb.build());
FlowModUtils.setActions(fmb, actions, sw);
log.debug("write drop flow-mod sw={} match={} flow-mod={}",
new Object[] { sw, mb.build(), fmb.build() });
// TODO: can't use the message damper since this method is static
sw.write(fmb.build());
return true;
}
示例14: writeFlowMod
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Writes a OFFlowMod to a switch.
* @param sw The switch tow rite the flowmod to.
* @param command The FlowMod actions (add, delete, etc).
* @param bufferId The buffer ID if the switch has buffered the packet.
* @param match The OFMatch structure to write.
* @param outPort The switch port to output it to.
*/
private void writeFlowMod(IOFSwitch sw, OFFlowModCommand command, OFBufferId bufferId,
Match match, OFPort outPort) {
// from openflow 1.0 spec - need to set these on a struct ofp_flow_mod:
// struct ofp_flow_mod {
// struct ofp_header header;
// struct ofp_match match; /* Fields to match */
// uint64_t cookie; /* Opaque controller-issued identifier. */
//
// /* Flow actions. */
// uint16_t command; /* One of OFPFC_*. */
// uint16_t idle_timeout; /* Idle time before discarding (seconds). */
// uint16_t hard_timeout; /* Max time before discarding (seconds). */
// uint16_t priority; /* Priority level of flow entry. */
// uint32_t buffer_id; /* Buffered packet to apply to (or -1).
// Not meaningful for OFPFC_DELETE*. */
// uint16_t out_port; /* For OFPFC_DELETE* commands, require
// matching entries to include this as an
// output port. A value of OFPP_NONE
// indicates no restriction. */
// uint16_t flags; /* One of OFPFF_*. */
// struct ofp_action_header actions[0]; /* The action length is inferred
// from the length field in the
// header. */
// };
OFFlowMod.Builder fmb;
if (command == OFFlowModCommand.DELETE) {
fmb = sw.getOFFactory().buildFlowDelete();
} else {
fmb = sw.getOFFactory().buildFlowAdd();
}
fmb.setMatch(match);
fmb.setCookie((U64.of(LearningSwitch.LEARNING_SWITCH_COOKIE)));
fmb.setIdleTimeout(LearningSwitch.FLOWMOD_DEFAULT_IDLE_TIMEOUT);
fmb.setHardTimeout(LearningSwitch.FLOWMOD_DEFAULT_HARD_TIMEOUT);
fmb.setPriority(LearningSwitch.FLOWMOD_PRIORITY);
fmb.setBufferId(bufferId);
fmb.setOutPort((command == OFFlowModCommand.DELETE) ? OFPort.ANY : outPort);
Set<OFFlowModFlags> sfmf = new HashSet<OFFlowModFlags>();
if (command != OFFlowModCommand.DELETE) {
sfmf.add(OFFlowModFlags.SEND_FLOW_REM);
}
fmb.setFlags(sfmf);
// set the ofp_action_header/out actions:
// from the openflow 1.0 spec: need to set these on a struct ofp_action_output:
// uint16_t type; /* OFPAT_OUTPUT. */
// uint16_t len; /* Length is 8. */
// uint16_t port; /* Output port. */
// uint16_t max_len; /* Max length to send to controller. */
// type/len are set because it is OFActionOutput,
// and port, max_len are arguments to this constructor
List<OFAction> al = new ArrayList<OFAction>();
al.add(sw.getOFFactory().actions().buildOutput().setPort(outPort).setMaxLen(0xffFFffFF).build());
fmb.setActions(al);
if (log.isTraceEnabled()) {
log.trace("{} {} flow mod {}",
new Object[]{ sw, (command == OFFlowModCommand.DELETE) ? "deleting" : "adding", fmb.build() });
}
counterFlowMod.increment();
// and write it out
sw.write(fmb.build());
}
示例15: writeMetadataFromString
import org.projectfloodlight.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Convert the string representation of an OFInstructionMetadata to
* an OFInstructionMetadata. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void writeMetadataFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
if (inst == null || inst.equals("")) {
return;
}
if (fmb.getVersion().compareTo(OFVersion.OF_11) < 0) {
log.error("Write Metadata Instruction not supported in OpenFlow 1.0");
return;
}
OFInstructionWriteMetadata.Builder ib = OFFactories.getFactory(fmb.getVersion()).instructions().buildWriteMetadata();
// Process tokens (should be metadata or its mask)
String[] keyValue = inst.split("/");
if (keyValue.length > 2) {
throw new IllegalArgumentException("[Metadata, Mask] " + keyValue + " does not have form 'metadata/mask' or 'metadata' for parsing " + inst);
} else if (keyValue.length == 1) {
log.debug("No mask detected in OFInstructionWriteMetaData string.");
} else if (keyValue.length == 2) {
log.debug("Detected mask in OFInstructionWriteMetaData string.");
}
// Get the metadata
if (keyValue[0].startsWith("0x")) {
ib.setMetadata(U64.of(Long.valueOf(keyValue[0].replaceFirst("0x", ""), 16)));
} else {
ib.setMetadata(U64.of(Long.valueOf(keyValue[0])));
}
// Get the optional mask
if (keyValue.length == 2) {
if (keyValue[1].startsWith("0x")) {
ib.setMetadataMask(U64.of(Long.valueOf(keyValue[1].replaceFirst("0x", ""), 16)));
} else {
ib.setMetadataMask(U64.of(Long.valueOf(keyValue[1])));
}
} else {
ib.setMetadataMask(U64.NO_MASK);
}
log.debug("Appending WriteMetadata instruction: {}", ib.build());
appendInstruction(fmb, ib.build());
log.debug("All instructions after append: {}", fmb.getInstructions());
}