本文整理汇总了Java中org.projectfloodlight.openflow.protocol.OFPacketOut类的典型用法代码示例。如果您正苦于以下问题:Java OFPacketOut类的具体用法?Java OFPacketOut怎么用?Java OFPacketOut使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OFPacketOut类属于org.projectfloodlight.openflow.protocol包,在下文中一共展示了OFPacketOut类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendDiscoveryMessage
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的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);
}
示例2: testCreate
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的package包/类
@Test
public void testCreate() {
OFPacketOut packetOut = pvs.generateVerificationPacket(sw1, sw1Port1.getPortNo());
expect(packetIn.getData()).andReturn(packetOut.getData());
expect(packetIn.getInPort()).andReturn(sw2Port1.getPortNo());
replay(packetIn);
byte[] d = packetIn.getData();
System.out.println(packetOut.toString());
System.out.println(Hex.encodeHexString(packetOut.getData()));
System.out.println(Hex.encodeHexString(d));
// Path path = new Path(sw2, sw2Port1.getPortNo(), verPacket);
// assertTrue(path.getSource().equals(sw1Port1));
// assertTrue(path.getDestination().equals(sw2Port1));
// assertEquals(path.getLatency(), 100);
}
示例3: testBcastPacket
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的package包/类
@SuppressWarnings("static-access")
@Test
public void testBcastPacket() {
// This is Broadcast so set dstIpTarget to the broadcast IP
InetSocketAddress dstIpTarget = new InetSocketAddress(pvs.VERIFICATION_PACKET_IP_DST, 200);
// Generate the VerificationPacket
OFPacketOut packet = pvs.generateVerificationPacket(sw1, OFPort.of(1));
System.out.println("packet: " + Hex.encodeHexString(packet.getData()));
// Source MAC will always be that of sw1 for both Unicast and Broadcast
byte[] srcMac = Arrays.copyOfRange(packet.getData(), 6, 12);
assertArrayEquals(MacAddress.of(sw1HwAddrTarget).getBytes(), srcMac);
// Destination MAC should be that of BROADCAST for Broadcast Packet
byte[] dstMac = Arrays.copyOfRange(packet.getData(), 0, 6);
assertArrayEquals(MacAddress.of(pvs.VERIFICATION_BCAST_PACKET_DST).getBytes(), dstMac);
// Source IP is actual switch1 IP
byte[] srcIpActual = Arrays.copyOfRange(packet.getData(), 26, 30);
assertArrayEquals(srcIpTarget.getAddress().getAddress(), srcIpActual);
// Destination IP is that of DESTINATION BROADCAST IP
byte[] dstIpActual = Arrays.copyOfRange(packet.getData(), 30, 34);
assertArrayEquals(dstIpTarget.getAddress().getAddress(), dstIpActual);
}
示例4: testUncastPacket
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的package包/类
@Test
public void testUncastPacket() {
// Generate the VerificationPacket
OFPacketOut packet = pvs.generateVerificationPacket(sw1, OFPort.of(1), sw2);
// Source MAC will always be that of sw1 for both Unicast and Broadcast
byte[] srcMacActual = Arrays.copyOfRange(packet.getData(), 6, 12);
assertArrayEquals(MacAddress.of(sw1HwAddrTarget).getBytes(), srcMacActual);
// Destination MAC should be that of sw2 for Unicast Packet
byte[] dstMacActual = Arrays.copyOfRange(packet.getData(), 0, 6);
assertArrayEquals(MacAddress.of(sw2HwAddrTarget).getBytes(), dstMacActual);
// Source and Destination IP's are the respective switch IP's
byte[] srcIpActual = Arrays.copyOfRange(packet.getData(), 26, 30);
assertArrayEquals(srcIpTarget.getAddress().getAddress(), srcIpActual);
byte[] dstIpActual = Arrays.copyOfRange(packet.getData(), 30, 34);
assertArrayEquals(dstIpTarget.getAddress().getAddress(), dstIpActual);
}
示例5: 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();
}
示例6: 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());
}
示例7: testSingleMessageWrite
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的package包/类
/** write a packetOut, which is not 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);
eventLoop.runTasks();
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));
}
示例8: testMessageWriteList
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的package包/类
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();
OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
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(ImmutableList.of(hello, packetOut));
eventLoop.runTasks();
assertThat("Write should have been written", 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(hello, packetOut));
}
示例9: 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());
}
示例10: testSingleMessageWrite
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的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));
}
示例11: testMessageWriteList
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的package包/类
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();
OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
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(ImmutableList.of(hello, packetOut));
assertThat("Write should have been written", 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(hello, packetOut));
}
示例12: 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();
}
示例13: addPort
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的package包/类
/**
* Add physical port port to discovery process.
* Send out initial LLDP and label it as slow port.
*
* @param port the port
*/
public void addPort(final OFPortDesc port) {
// Ignore ports that are not on this switch, or already booted. */
this.ports.put(port.getPortNo().getPortNumber(), port);
synchronized (this) {
this.log.debug("sending init probe to port {}",
port.getPortNo().getPortNumber());
OFPacketOut pkt;
pkt = this.createLLDPPacketOut(port);
this.sw.sendMsg(pkt);
if (useBDDP) {
OFPacketOut bpkt = this.createBDDPPacketOut(port);
this.sw.sendMsg(bpkt);
}
this.slowPorts.add(port.getPortNo().getPortNumber());
}
}
示例14: 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();
}
示例15: createBDDPPacketOut
import org.projectfloodlight.openflow.protocol.OFPacketOut; //导入依赖的package包/类
/**
* Creates packet_out BDDP for specified output port.
*
* @param port the port
* @return Packet_out message with LLDP data
*/
private OFPacketOut createBDDPPacketOut(final OFPortDesc port) {
if (port == null) {
return null;
}
OFPacketOut.Builder packetOut = sw.factory().buildPacketOut();
packetOut.setBufferId(OFBufferId.NO_BUFFER);
OFActionOutput.Builder act = sw.factory().actions().buildOutput()
.setPort(port.getPortNo());
OFAction out = act.build();
packetOut.setActions(Collections.singletonList(out));
this.lldpPacket.setPort(port.getPortNo().getPortNumber());
this.bddpEth.setSourceMACAddress(port.getHwAddr().getBytes());
final byte[] bddp = this.bddpEth.serialize();
packetOut.setData(bddp);
return packetOut.build();
}