本文整理汇总了Java中net.floodlightcontroller.core.IOFSwitch.write方法的典型用法代码示例。如果您正苦于以下问题:Java IOFSwitch.write方法的具体用法?Java IOFSwitch.write怎么用?Java IOFSwitch.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.floodlightcontroller.core.IOFSwitch
的用法示例。
在下文中一共展示了IOFSwitch.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteMeter
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
public ImmutablePair<Long, Boolean> deleteMeter(IOFSwitch sw, final DatapathId dpid, final long meterId) {
logger.debug("deleting meter {} from switch {}", meterId, dpid);
OFFactory ofFactory = sw.getOFFactory();
OFMeterMod.Builder meterDeleteBuilder = ofFactory.buildMeterMod()
.setMeterId(meterId)
.setCommand(OFMeterModCommand.DELETE);
if (sw.getOFFactory().getVersion().compareTo(OF_13) > 0) {
meterDeleteBuilder.setBands(emptyList());
} else {
meterDeleteBuilder.setMeters(emptyList());
}
OFMeterMod meterDelete = meterDeleteBuilder.build();
boolean response = sw.write(meterDelete);
return new ImmutablePair<>(meterDelete.getXid(), response);
}
示例2: writePacketOutForPacketIn
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
/**
* Writes an OFPacketOut message to a switch.
* @param sw The switch to write the PacketOut to.
* @param packetInMessage The corresponding PacketIn.
* @param egressPort The switchport to output the PacketOut.
*/
private void writePacketOutForPacketIn(IOFSwitch sw, OFPacketIn packetInMessage, OFPort egressPort) {
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
// Set buffer_id, in_port, actions_len
pob.setBufferId(packetInMessage.getBufferId());
pob.setInPort(packetInMessage.getVersion().compareTo(OFVersion.OF_12) < 0 ? packetInMessage.getInPort() : packetInMessage.getMatch().get(MatchField.IN_PORT));
// set actions
List<OFAction> actions = new ArrayList<OFAction>(1);
actions.add(sw.getOFFactory().actions().buildOutput().setPort(egressPort).setMaxLen(0xffFFffFF).build());
pob.setActions(actions);
// set data - only if buffer_id == -1
if (packetInMessage.getBufferId() == OFBufferId.NO_BUFFER) {
byte[] packetData = packetInMessage.getData();
pob.setData(packetData);
}
// and write it out
counterPacketOut.increment();
sw.write(pob.build());
}
示例3: sendDiscoveryMessage
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
@Override
public boolean sendDiscoveryMessage(DatapathId srcSwId, OFPort port, DatapathId dstSwId) {
IOFSwitch srcSwitch = switchService.getSwitch(srcSwId);
if (srcSwitch == null) { // fix dereference violations in case race conditions
return false;
}
if (dstSwId == null) {
return srcSwitch.write(generateVerificationPacket(srcSwitch, port));
}
IOFSwitch dstSwitch = switchService.getSwitch(dstSwId);
OFPacketOut ofPacketOut = generateVerificationPacket(srcSwitch, port, dstSwitch);
logger.debug("sending verification packet out {}/{}: {}", srcSwitch.getId().toString(), port.getPortNumber(),
Hex.encodeHexString(ofPacketOut.getData()));
return srcSwitch.write(ofPacketOut);
}
示例4: write
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
/**
* write the message to the switch according to our dampening settings
* @param sw
* @param msg
* @return true if the message was written to the switch, false if
* the message was dampened.
* @throws IOException
*/
public boolean write(IOFSwitch sw, OFMessage msg) throws IOException {
if (!msgTypesToCache.contains(msg.getType())) {
sw.write(msg);
return true;
}
DamperEntry entry = new DamperEntry(msg, sw);
if (cache.update(entry)) {
// entry exists in cache. Dampening.
return false;
} else {
sw.write(msg);
return true;
}
}
示例5: receive
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
OFMessage outMessage;
HubType ht = HubType.USE_PACKET_OUT;
switch (ht) {
case USE_FLOW_MOD:
outMessage = createHubFlowMod(sw, msg);
break;
default:
case USE_PACKET_OUT:
outMessage = createHubPacketOut(sw, msg);
break;
}
sw.write(outMessage);
return Command.CONTINUE;
}
示例6: sendDiscoveryMessage
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的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());
}
示例7: clearFlowMods
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
/**
* @param sw
* The switch we wish to remove flows from
* @param match
* The specific OFMatch object of specific flows we wish to
* delete
* @param outPort
* The specific Output Action OutPort of specific flows we wish
* to delete
*/
public void clearFlowMods(IOFSwitch sw, Match match, OFPort outPort) {
// Delete pre-existing flows with the same match, and output action port
// or outPort
OFFlowDelete fm = sw.getOFFactory().buildFlowDelete()
.setMatch(match)
.setOutPort(outPort)
.build();
try {
sw.write(fm);
} catch (Exception e) {
log.error("Failed to clear flows on switch {} - {}", this, e);
}
}
示例8: writeOFMessagesToSwitch
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
/**
* Writes a list of OFMessages to a switch
* @param dpid The datapath ID of the switch to write to
* @param messages The list of OFMessages to write.
*/
private void writeOFMessagesToSwitch(DatapathId dpid, List<OFMessage> messages) {
IOFSwitch ofswitch = switchService.getSwitch(dpid);
if (ofswitch != null) { // is the switch connected
if (log.isDebugEnabled()) {
log.debug("Sending {} new entries to {}", messages.size(), dpid);
}
ofswitch.write(messages);
}
}
示例9: installMeter
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
private ImmutablePair<Long, Boolean> installMeter(final IOFSwitch sw, final DatapathId dpid, final long bandwidth,
final long burstSize, final long meterId) {
logger.debug("installing meter {} on switch {} width bandwidth {}", meterId, dpid, bandwidth);
Set<OFMeterFlags> flags = new HashSet<>(Arrays.asList(OFMeterFlags.KBPS, OFMeterFlags.BURST));
OFFactory ofFactory = sw.getOFFactory();
OFMeterBandDrop.Builder bandBuilder = ofFactory.meterBands()
.buildDrop()
.setRate(bandwidth)
.setBurstSize(burstSize);
OFMeterMod.Builder meterModBuilder = ofFactory.buildMeterMod()
.setMeterId(meterId)
.setCommand(OFMeterModCommand.ADD)
.setFlags(flags);
if (sw.getOFFactory().getVersion().compareTo(OF_13) > 0) {
meterModBuilder.setBands(singletonList(bandBuilder.build()));
} else {
meterModBuilder.setMeters(singletonList(bandBuilder.build()));
}
OFMeterMod meterMod = meterModBuilder.build();
boolean response = sw.write(meterMod);
return new ImmutablePair<>(meterMod.getXid(), response);
}
示例10: writeOFMessageToSwitch
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
/**
* Writes a single OFMessage to a switch
* @param dpid The datapath ID of the switch to write to
* @param message The OFMessage to write.
*/
private void writeOFMessageToSwitch(DatapathId dpid, OFMessage message) {
IOFSwitch ofswitch = switchService.getSwitch(dpid);
if (ofswitch != null) { // is the switch connected
if (log.isDebugEnabled()) {
log.debug("Sending 1 new entries to {}", dpid.toString());
}
ofswitch.write(message);
}
}
示例11: writeFlowModToSwitch
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
/**
* Writes an OFFlowMod to a switch
* @param sw The IOFSwitch to write to
* @param flowMod The OFFlowMod to write
*/
@LogMessageDoc(level="ERROR",
message="Tried to write OFFlowMod to {switch} but got {error}",
explanation="An I/O error occured while trying to write a " +
"static flow to a switch",
recommendation=LogMessageDoc.CHECK_SWITCH)
private void writeFlowModToSwitch(IOFSwitch sw, OFFlowMod flowMod) {
sw.write(flowMod);
sw.flush();
}
示例12: sendDiscoveryMessage
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的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
*/
@LogMessageDoc(level = "ERROR",
message = "Failure sending LLDP out port {port} on switch {switch}",
explanation = "An I/O error occured while sending LLDP message "
+ "to the switch.",
recommendation = LogMessageDoc.CHECK_SWITCH)
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);
OFPortDesc ofpPort = iofSwitch.getPort(port);
if (log.isTraceEnabled()) {
log.trace("Sending LLDP packet out of swich: {}, port: {}",
sw.toString(), port.getPortNumber());
}
OFPacketOut po = generateLLDPMessage(sw, 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());
iofSwitch.flush();
}
示例13: enforceMirrorAction
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
private void enforceMirrorAction(FPContext cntx, MirrorAction ma){
//check if the mirrored switch and port are still active
IOFSwitch sw = switchService.getSwitch(DatapathId.of(ma.getDPID()));
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx.getFlowContext(),
IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if (sw == null){
log.error("[FRESCO] Cannot mirrow packet since the destination switch is offline");
return;
}
if (sw.getPort(OFPort.of(ma.getPortID())) == null){
log.error("[FRESCO] Cannot mirrow packet since the destination port is closed");
return;
}
//use packet-out to send out packet to a specific switch port
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
ArrayList<OFAction> actions = new ArrayList<OFAction>();
actions.add(sw.getOFFactory().actions().output(OFPort.of(ma.getPortID()),Integer.MAX_VALUE));
byte[] packetData = eth.serialize();
pob.setData(packetData);
sw.write(pob.build());
}
示例14: pushPacket
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
/**
* used to push any packet - borrowed routine from Forwarding
*
* @param OFPacketIn pi
* @param IOFSwitch sw
* @param int bufferId
* @param short inPort
* @param short outPort
* @param List<OFAction> actions
*/
public void pushPacket(IPacket packet,
IOFSwitch sw,
OFBufferId bufferId,
OFPort inPort,
OFPort outPort,
List<OFAction> actions
) {
log.trace("PacketOut srcSwitch={} inPort={} outPort={}", new Object[] {sw, inPort, outPort});
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
// set actions
//List<OFAction> actions = new ArrayList<OFAction>();
actions.add(sw.getOFFactory().actions().buildOutput().setPort(outPort).setMaxLen(Integer.MAX_VALUE).build());
pob.setActions(actions);
// set buffer_id, in_port
pob.setBufferId(bufferId);
pob.setInPort(inPort);
// set data - only if buffer_id == -1
if (pob.getBufferId() == OFBufferId.NO_BUFFER) {
if (packet == null) {
log.error("BufferId is not set and packet data is null. " +
"Cannot send packetOut. " +
"srcSwitch={} inPort={} outPort={}",
new Object[] {sw, inPort, outPort});
return;
}
byte[] packetData = packet.serialize();
pob.setData(packetData);
}
//counterPacketOut.increment();
sw.write(pob.build());
}
示例15: clearFlowMods
import net.floodlightcontroller.core.IOFSwitch; //导入方法依赖的package包/类
/**
* @param sw
* The switch we wish to remove flows from
* @param outPort
* The specific Output Action OutPort of specific flows we wish
* to delete
*/
public void clearFlowMods(IOFSwitch sw, OFPort outPort) {
// Delete all pre-existing flows with the same output action port or
// outPort
Match match = sw.getOFFactory().buildMatch().build();
OFFlowDelete fm = sw.getOFFactory().buildFlowDelete()
.setMatch(match)
.setOutPort(outPort)
.build();
try {
sw.write(fm);
} catch (Exception e) {
log.error("Failed to clear flows on switch {} - {}", this, e);
}
}