本文整理汇总了Java中org.projectfloodlight.openflow.protocol.OFPacketOut.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java OFPacketOut.Builder方法的具体用法?Java OFPacketOut.Builder怎么用?Java OFPacketOut.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.projectfloodlight.openflow.protocol.OFPacketOut
的用法示例。
在下文中一共展示了OFPacketOut.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHubPacketOut
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的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();
}
示例2: sendDiscoveryMessage
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的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());
}
示例3: writePacketOutForPacketIn
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的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());
}
示例4: createLLDPPacketOut
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
* Creates packet_out LLDP for specified output port.
*
* @param port the port
* @return Packet_out message with LLDP data
*/
private OFPacketOut createLLDPPacketOut(final OFPortDesc port) {
if (port == null) {
return null;
}
OFPacketOut.Builder packetOut = this.ofFactory.buildPacketOut();
packetOut.setBufferId(OFBufferId.NO_BUFFER);
OFAction act = this.ofFactory.actions().buildOutput()
.setPort(port.getPortNo()).build();
packetOut.setActions(Collections.singletonList(act));
this.lldpPacket.setPort(port.getPortNo().getPortNumber());
this.ethPacket.setSourceMACAddress(port.getHwAddr().getBytes());
final byte[] lldp = this.ethPacket.serialize();
packetOut.setData(lldp);
return packetOut.build();
}
示例5: createOFPacketOut
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
private OFPacketOut createOFPacketOut(byte[] data, OFAction act, long xid) {
OFPacketOut.Builder builder = sw.factory().buildPacketOut();
if (sw.factory().getVersion().getWireVersion() <= OFVersion.OF_14.getWireVersion()) {
return builder.setXid(xid)
.setInPort(pktinInPort())
.setBufferId(OFBufferId.NO_BUFFER)
.setData(data)
// .setBufferId(pktin.getBufferId())
.setActions(Collections.singletonList(act)).build();
}
return builder.setXid(xid)
.setBufferId(OFBufferId.NO_BUFFER)
.setActions(Collections.singletonList(act))
.setData(data)
.build();
}
示例6: returnPacketToSwitch
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
public void returnPacketToSwitch(IOFSwitch sw, OFPacketIn pi, ArrayList<OFAction> actionList) {
OFPacketOut.Builder po = sw.getOFFactory().buildPacketOut();
po.setBufferId(pi.getBufferId()).setInPort(OFPort.ANY).setActions(actionList);
// Packet might be buffered in the switch or encapsulated in Packet-In
if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
//Packet is encapsulated -> send it back
byte[] packetData = pi.getData();
po.setData(packetData);
}
log.info("PACKETOUT : returning packet back to the switch");
sw.write(po.build());
}
示例7: build
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
@Override
public void build(OFPort outPort) {
if (isBuilt.getAndSet(true)) {
return;
}
OFPacketOut.Builder builder = sw.factory().buildPacketOut();
OFAction act = buildOutput(outPort.getPortNumber());
pktout = builder.setXid(pktin.getXid())
.setInPort(pktinInPort())
.setBufferId(OFBufferId.NO_BUFFER)
.setData(pktin.getData())
// .setBufferId(pktin.getBufferId())
.setActions(Collections.singletonList(act))
.build();
}
示例8: packetOut
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
private OFPacketOut packetOut(OpenFlowSwitch sw, byte[] eth, OFPort out) {
OFPacketOut.Builder builder = sw.factory().buildPacketOut();
OFAction act = sw.factory().actions()
.buildOutput()
.setPort(out)
.build();
return builder
.setBufferId(OFBufferId.NO_BUFFER)
.setInPort(OFPort.CONTROLLER)
.setActions(Collections.singletonList(act))
.setData(eth)
.build();
}
示例9: enforceMirrorAction
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的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());
}
示例10: sendDiscoveryMessage
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的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();
}
示例11: packetOutMultiPort
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
* Write packetout message to sw with output actions to one or more
* output ports with inPort/outPorts passed in.
* @param packetData
* @param sw
* @param inPort
* @param ports
* @param cntx
*/
public void packetOutMultiPort(byte[] packetData, IOFSwitch sw,
OFPort inPort, Set<OFPort> outPorts, FloodlightContext cntx) {
//setting actions
List<OFAction> actions = new ArrayList<OFAction>();
Iterator<OFPort> j = outPorts.iterator();
while (j.hasNext()) {
actions.add(sw.getOFFactory().actions().output(j.next(), 0));
}
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
pob.setActions(actions);
pob.setBufferId(OFBufferId.NO_BUFFER);
pob.setInPort(inPort);
pob.setData(packetData);
try {
if (log.isTraceEnabled()) {
log.trace("write broadcast packet on switch-id={} " +
"interfaces={} packet-out={}",
new Object[] {sw.getId(), outPorts, pob.build()});
}
messageDamper.write(sw, pob.build());
} catch (IOException e) {
log.error("Failure writing packet out", e);
}
}
示例12: writePacketOutForPacketIn
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的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.
*/
public static 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
sw.write(pob.build());
}
示例13: pushPacket
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的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());
}
示例14: doFlood
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
* Creates a OFPacketOut with the OFPacketIn data that is flooded on all ports unless
* the port is blocked, in which case the packet will be dropped.
* @param sw The switch that receives the OFPacketIn
* @param pi The OFPacketIn that came to the switch
* @param cntx The FloodlightContext associated with this OFPacketIn
*/
protected void doFlood(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));
// Set Action to flood
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
List<OFAction> actions = new ArrayList<OFAction>();
Set<OFPort> broadcastPorts = this.topologyService.getSwitchBroadcastPorts(sw.getId());
if (broadcastPorts == null) {
log.debug("BroadcastPorts returned null. Assuming single switch w/no links.");
/* Must be a single-switch w/no links */
broadcastPorts = Collections.singleton(OFPort.FLOOD);
}
for (OFPort p : broadcastPorts) {
if (p.equals(inPort)) continue;
actions.add(sw.getOFFactory().actions().output(p, Integer.MAX_VALUE));
}
pob.setActions(actions);
// log.info("actions {}",actions);
// set buffer-id, in-port and packet-data based on packet-in
pob.setBufferId(OFBufferId.NO_BUFFER);
pob.setInPort(inPort);
pob.setData(pi.getData());
try {
if (log.isTraceEnabled()) {
log.trace("Writing flood PacketOut switch={} packet-in={} packet-out={}",
new Object[] {sw, pi, pob.build()});
}
messageDamper.write(sw, pob.build());
} catch (IOException e) {
log.error("Failure writing PacketOut switch={} packet-in={} packet-out={}",
new Object[] {sw, pi, pob.build()}, e);
}
return;
}
示例15: doFlood
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
* Creates a OFPacketOut with the OFPacketIn data that is flooded on all ports unless
* the port is blocked, in which case the packet will be dropped.
* @param sw The switch that receives the OFPacketIn
* @param pi The OFPacketIn that came to the switch
* @param cntx The FloodlightContext associated with this OFPacketIn
*/
protected void doFlood(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));
// Set Action to flood
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
List<OFAction> actions = new ArrayList<OFAction>();
Set<OFPort> broadcastPorts = this.topologyService.getSwitchBroadcastPorts(sw.getId());
if (broadcastPorts == null) {
log.debug("BroadcastPorts returned null. Assuming single switch w/no links.");
/* Must be a single-switch w/no links */
broadcastPorts = Collections.singleton(OFPort.FLOOD);
}
for (OFPort p : broadcastPorts) {
if (p.equals(inPort)) continue;
actions.add(sw.getOFFactory().actions().output(p, Integer.MAX_VALUE));
}
pob.setActions(actions);
// log.info("actions {}",actions);
// set buffer-id, in-port and packet-data based on packet-in
pob.setBufferId(OFBufferId.NO_BUFFER);
pob.setInPort(inPort);
pob.setData(pi.getData());
try {
if (log.isTraceEnabled()) {
log.trace("Writing flood PacketOut switch={} packet-in={} packet-out={}",
new Object[] {sw, pi, pob.build()});
}
messageDamper.write(sw, pob.build());
} catch (IOException e) {
log.error("Failure writing PacketOut switch={} packet-in={} packet-out={}",
new Object[] {sw, pi, pob.build()}, e);
}
return;
}