本文整理汇总了Java中org.projectfloodlight.openflow.protocol.action.OFAction类的典型用法代码示例。如果您正苦于以下问题:Java OFAction类的具体用法?Java OFAction怎么用?Java OFAction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OFAction类属于org.projectfloodlight.openflow.protocol.action包,在下文中一共展示了OFAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: installTransitFlow
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public ImmutablePair<Long, Boolean> installTransitFlow(final DatapathId dpid, final String flowId,
final Long cookie, final int inputPort, final int outputPort,
final int transitVlanId) {
List<OFAction> actionList = new ArrayList<>();
IOFSwitch sw = ofSwitchService.getSwitch(dpid);
// build match by input port and transit vlan id
Match match = matchFlow(sw, inputPort, transitVlanId);
// transmit packet from outgoing port
actionList.add(actionSetOutputPort(sw, outputPort));
// build instruction with action list
OFInstructionApplyActions actions = buildInstructionApplyActions(sw, actionList);
// build FLOW_MOD command, no meter
OFFlowMod flowMod = buildFlowMod(sw, match, null, actions,
cookie & FLOW_COOKIE_MASK, FlowModUtils.PRIORITY_VERY_HIGH);
// send FLOW_MOD to the switch
boolean response = pushFlow(flowId, dpid, flowMod);
return new ImmutablePair<>(flowMod.getXid(), response);
}
示例2: replaceSchemeOutputVlanTypeToOFActionList
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
/**
* Builds OFAction list based on flow parameters for replace scheme.
*
* @param sw IOFSwitch instance
* @param outputVlanId set vlan on packet before forwarding via outputPort; 0 means not to set
* @param outputVlanType type of action to apply to the outputVlanId if greater than 0
* @return list of {@link OFAction}
*/
private List<OFAction> replaceSchemeOutputVlanTypeToOFActionList(IOFSwitch sw, int outputVlanId,
OutputVlanType outputVlanType) {
List<OFAction> actionList;
switch (outputVlanType) {
case PUSH:
case REPLACE:
actionList = singletonList(actionReplaceVlan(sw, outputVlanId));
break;
case POP:
case NONE:
actionList = singletonList(actionPopVlan(sw));
break;
default:
actionList = emptyList();
logger.error("Unknown OutputVlanType: " + outputVlanType);
}
return actionList;
}
示例3: pushSchemeOutputVlanTypeToOFActionList
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
/**
* Builds OFAction list based on flow parameters for push scheme.
*
* @param sw IOFSwitch instance
* @param outputVlanId set vlan on packet before forwarding via outputPort; 0 means not to set
* @param outputVlanType type of action to apply to the outputVlanId if greater than 0
* @return list of {@link OFAction}
*/
private List<OFAction> pushSchemeOutputVlanTypeToOFActionList(IOFSwitch sw, int outputVlanId,
OutputVlanType outputVlanType) {
List<OFAction> actionList = new ArrayList<>(2);
switch (outputVlanType) {
case PUSH: // No VLAN on packet so push a new one
actionList.add(actionPushVlan(sw, ETH_TYPE));
actionList.add(actionReplaceVlan(sw, outputVlanId));
break;
case REPLACE: // VLAN on packet but needs to be replaced
actionList.add(actionReplaceVlan(sw, outputVlanId));
break;
case POP: // VLAN on packet, so remove it
// TODO: can i do this? pop two vlan's back to back...
actionList.add(actionPopVlan(sw));
break;
case NONE:
break;
default:
logger.error("Unknown OutputVlanType: " + outputVlanType);
}
return actionList;
}
示例4: actionReplaceVlan
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
/**
* Create an OFAction to change the outer most vlan.
*
* @param sw switch object
* @param newVlan final VLAN to be set on the packet
* @return {@link OFAction}
*/
private OFAction actionReplaceVlan(final IOFSwitch sw, final int newVlan) {
OFFactory factory = sw.getOFFactory();
OFOxms oxms = factory.oxms();
OFActions actions = factory.actions();
if (OF_12.compareTo(factory.getVersion()) == 0) {
return actions.buildSetField().setField(oxms.buildVlanVid()
.setValue(OFVlanVidMatch.ofRawVid((short) newVlan))
.build()).build();
} else {
return actions.buildSetField().setField(oxms.buildVlanVid()
.setValue(OFVlanVidMatch.ofVlan(newVlan))
.build()).build();
}
}
示例5: installVerificationRule
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
/**
* Installs the verification rule
*
* @param dpid datapathId of switch
* @param isBroadcast if broadcast then set a generic match; else specific to switch Id
* @return true if the command is accepted to be sent to switch, false otherwise - switch is disconnected or in
* SLAVE mode
*/
private boolean installVerificationRule(final DatapathId dpid, final boolean isBroadcast) {
IOFSwitch sw = ofSwitchService.getSwitch(dpid);
Match match = matchVerification(sw, isBroadcast);
ArrayList<OFAction> actionList = new ArrayList<>(2);
actionList.add(actionSendToController(sw));
actionList.add(actionSetDstMac(sw, dpidToMac(sw)));
OFInstructionApplyActions instructionApplyActions = sw.getOFFactory().instructions()
.applyActions(actionList).createBuilder().build();
final long cookie = isBroadcast ? 0x8000000000000002L : 0x8000000000000003L;
OFFlowMod flowMod = buildFlowMod(sw, match, null, instructionApplyActions,
cookie, FlowModUtils.PRIORITY_VERY_HIGH);
String flowname = (isBroadcast) ? "Broadcast" : "Unicast";
flowname += "--VerificationFlow--" + dpid.toString();
return pushFlow(flowname, dpid, flowMod);
}
示例6: testSingleMessageWrite
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
/** write a packetOut, which is buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();
OFPacketOut packetOut = factory.buildPacketOut()
.setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
.setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
.build();
conn.write(packetOut);
assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));
List<OFMessage> value = cMsgList.getValue();
logger.info("Captured channel write: "+value);
assertThat("Should have captured MsgList", cMsgList.getValue(),
Matchers.<OFMessage> contains(packetOut));
}
示例7: mapAction
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
@Override
public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException {
if (action.getType().equals(OFActionType.SET_FIELD)) {
OFActionSetField setFieldAction = (OFActionSetField) action;
OFOxm<?> oxm = setFieldAction.getField();
switch (oxm.getMatchField().id) {
case VLAN_VID:
OFOxmVlanVid vlanVid = (OFOxmVlanVid) oxm;
return new OfdpaSetVlanVid(VlanId.vlanId(vlanVid.getValue().getRawVid()));
default:
throw new UnsupportedOperationException(
"Driver does not support extension type " + oxm.getMatchField().id);
}
}
throw new UnsupportedOperationException(
"Unexpected OFAction: " + action.toString());
}
示例8: rewriteActions
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
/**
* Rewrite actions to use LINC OF optical extensions.
*
* @param actions original actions
* @return rewritten actions
*/
private List<OFAction> rewriteActions(List<OFAction> actions) {
List<OFAction> newActions = new LinkedList<>();
for (OFAction action : actions) {
if (!(action instanceof OFActionSetField)) {
newActions.add(action);
continue;
}
OFActionSetField sf = (OFActionSetField) action;
if (!(sf.getField() instanceof OFOxmExpOchSigId)) {
newActions.add(action);
continue;
}
OFOxmExpOchSigId oxm = (OFOxmExpOchSigId) sf.getField();
CircuitSignalID signalId = oxm.getValue();
newActions.add(
factory().actions().circuit(factory().oxms().ochSigid(signalId)));
}
return newActions;
}
示例9: sendMsg
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
@Override
public void sendMsg(OFMessage msg) {
// Ignore everything but flow mods and stat requests
if (!(msg instanceof OFFlowMod || msg instanceof OFFlowStatsRequest)) {
super.sendMsg(msg);
return;
}
Match newMatch;
OFMessage newMsg = null;
if (msg instanceof OFFlowStatsRequest) {
// Rewrite match only
OFFlowStatsRequest fsr = (OFFlowStatsRequest) msg;
newMatch = rewriteMatch(fsr.getMatch());
newMsg = fsr.createBuilder().setMatch(newMatch).build();
} else if (msg instanceof OFFlowMod) {
// Rewrite match and actions
OFFlowMod fm = (OFFlowMod) msg;
newMatch = rewriteMatch(fm.getMatch());
List<OFAction> actions = rewriteActions(fm.getActions());
newMsg = fm.createBuilder().setMatch(newMatch).setActions(actions).build();
}
super.sendMsg(newMsg);
}
示例10: buildL1Modification
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
private OFAction buildL1Modification(Instruction i) {
L1ModificationInstruction l1m = (L1ModificationInstruction) i;
OFOxm<?> oxm = null;
switch (l1m.subtype()) {
case ODU_SIGID:
ModOduSignalIdInstruction modOduSignalIdInstruction = (ModOduSignalIdInstruction) l1m;
OduSignalId oduSignalId = modOduSignalIdInstruction.oduSignalId();
OduSignalID oduSignalID = new OduSignalID((short) oduSignalId.tributaryPortNumber(),
(short) oduSignalId.tributarySlotLength(),
oduSignalId.tributarySlotBitmap());
oxm = factory().oxms().expOduSigId(oduSignalID);
break;
default:
log.warn("Unimplemented action type {}.", l1m.subtype());
break;
}
if (oxm != null) {
return factory().actions().buildSetField().setField(oxm).build();
}
return null;
}
示例11: buildFlowAdd
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
@Override
public OFFlowAdd buildFlowAdd() {
Match match = buildMatch();
List<OFAction> actions = buildActions();
long cookie = flowRule().id().value();
OFFlowAdd fm = factory().buildFlowAdd()
.setXid(xid)
.setCookie(U64.of(cookie))
.setBufferId(OFBufferId.NO_BUFFER)
.setActions(actions)
.setMatch(match)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
.setPriority(flowRule().priority())
.build();
return fm;
}
示例12: buildFlowMod
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
@Override
public OFFlowMod buildFlowMod() {
Match match = buildMatch();
List<OFAction> actions = buildActions();
long cookie = flowRule().id().value();
OFFlowMod fm = factory().buildFlowModify()
.setXid(xid)
.setCookie(U64.of(cookie))
.setBufferId(OFBufferId.NO_BUFFER)
.setActions(actions)
.setMatch(match)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
.setPriority(flowRule().priority())
.build();
return fm;
}
示例13: createFRESCOFlowMod
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的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();
}
示例14: createHubPacketOut
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
OFPacketIn pi = (OFPacketIn) msg;
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));
// set actions
OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
actionBuilder.setPort(OFPort.FLOOD);
pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));
// set data if it is included in the packetin
if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
byte[] packetData = pi.getData();
pob.setData(packetData);
}
return pob.build();
}
示例15: sendDiscoveryMessage
import org.projectfloodlight.openflow.protocol.action.OFAction; //导入依赖的package包/类
/**
* Send link discovery message out of a given switch port. The discovery
* message may be a standard LLDP or a modified LLDP, where the dst mac
* address is set to :ff. TODO: The modified LLDP will updated in the future
* and may use a different eth-type.
*
* @param sw
* @param port
* @param isStandard
* indicates standard or modified LLDP
* @param isReverse
* indicates whether the LLDP was sent as a response
*/
protected void sendDiscoveryMessage(DatapathId sw, OFPort port,
boolean isStandard, boolean isReverse) {
// Takes care of all checks including null pointer checks.
if (!isOutgoingDiscoveryAllowed(sw, port, isStandard, isReverse))
return;
IOFSwitch iofSwitch = switchService.getSwitch(sw);
if (iofSwitch == null) //fix dereference violations in case race conditions
return;
OFPortDesc ofpPort = iofSwitch.getPort(port);
OFPacketOut po = generateLLDPMessage(iofSwitch, port, isStandard, isReverse);
OFPacketOut.Builder pob = po.createBuilder();
// Add actions
List<OFAction> actions = getDiscoveryActions(iofSwitch, ofpPort.getPortNo());
pob.setActions(actions);
// no need to set length anymore
// send
// no more try-catch. switch will silently fail
iofSwitch.write(pob.build());
}