本文整理汇总了Java中org.openflow.protocol.OFPacketOut类的典型用法代码示例。如果您正苦于以下问题:Java OFPacketOut类的具体用法?Java OFPacketOut怎么用?Java OFPacketOut使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OFPacketOut类属于org.openflow.protocol包,在下文中一共展示了OFPacketOut类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAllowedPacketOutALL
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
/**
* tests packetOut event slicing
*/
@Test
public void testAllowedPacketOutALL(){
OFPacketOut out = new OFPacketOut();
List<OFAction> actions = new ArrayList<OFAction>();
OFActionOutput output = new OFActionOutput();
output.setType(OFActionType.OUTPUT);
output.setPort(OFPort.OFPP_ALL.getValue());
actions.add(output);
out.setActions(actions);
Ethernet pkt = new Ethernet();
pkt.setVlanID((short)1000);
pkt.setDestinationMACAddress("aa:bb:cc:dd:ee:ff");
pkt.setSourceMACAddress("ff:ee:dd:cc:bb:aa");
pkt.setEtherType((short)35020);
out.setPacketData(pkt.serialize());
List<OFMessage> outPackets = slicer.allowedPacketOut(out);
assertTrue("OutPacket size is correct, expected 5 got " + outPackets.size(), outPackets.size() == 5);
}
示例2: assertPacketOut
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
protected void assertPacketOut(OFMessage ofm, byte[] packetData,
Short[] ports) {
assertNotNull(ofm);
assertNotNull(ports);
assertEquals(true, ofm instanceof OFPacketOut);
OFPacketOut ofpo = (OFPacketOut) ofm;
List<OFAction> actions = ofpo.getActions();
assertEquals(ports.length, actions.size());
HashSet<Short> packetOutPorts = new HashSet<Short>();
for (OFAction action: actions) {
assertEquals(true, action instanceof OFActionOutput);
OFActionOutput a = (OFActionOutput)action;
packetOutPorts.add(a.getPort());
}
Arrays.sort(ports);
Short[] packetOutPortsArray =
packetOutPorts.toArray(new Short[0]);
Arrays.sort(packetOutPortsArray);
assertArrayEquals(ports, packetOutPortsArray);
if (packetData != null) {
// a mismatch here usually indicates that something
// went wrong with rewriting.
assertArrayEquals(packetData, ofpo.getPacketData());
}
}
示例3: addPort
import org.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 PhysicalPort port) {
// Ignore ports that are not on this switch
if (port.getParentSwitch().equals(this.sw)) {
synchronized (this) {
this.log.debug("sending init probe to port {}",
port.getPortNumber());
OFPacketOut pkt;
try {
pkt = this.createLLDPPacketOut(port);
this.sendMsg(pkt, this);
if (useBDDP) {
OFPacketOut bpkt = this.createBDDPPacketOut(port);
this.sendMsg(bpkt, this);
}
} catch (PortMappingException e) {
log.warn(e.getMessage());
return;
}
this.slowPorts.add(port.getPortNumber());
this.slowIterator = this.slowPorts.iterator();
}
}
}
示例4: createPacketOut
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
private OFPacketOut createPacketOut() {
//["packet", {"outport": 1, "protocol": 2, "header_len": 14, "inport": 2,
// "dstip": [49, 48, 46, 48, 46, 48, 46, 49],
// "srcmac": [99, 101, 58, 97, 56, 58, 100, 100, 58, 99, 102, 58, 49, 99, 58, 97, 101], "dstmac": [99, 101, 58, 97, 54, 58, 99, 51, 58, 100, 100, 58, 56, 57, 58, 99, 51],
// "raw": [206, 166, 195, 221, 137, 195, 206, 168, 221, 207, 28, 174, 8, 6, 0, 1, 8, 0, 6, 4, 0, 2, 206, 168, 221, 207, 28, 174, 10, 0, 0, 2, 206, 166, 195, 221, 137, 195, 10, 0, 0, 1],
// "payload_len": 42, "switch": 1, "ethtype": 2054, "srcip": [49, 48, 46, 48, 46, 48, 46, 50] }] + TERM_CHAR
OFPacketOut packetOut = new OFPacketOut();
packetOut.setBufferId(10);
packetOut.setInPort((short)2);
packetOut.setPacketData(new byte[] {28, 8, 6, 0, 1, 8, 0, 6, 4, 0, 2, 28, 10, 0, 0, 2, 10, 0, 0, 1});
BasicFactory factory = new BasicFactory();
packetOut.setActionFactory(factory.getActionFactory());
List<OFAction> actions = new ArrayList<OFAction>();
OFAction action = new OFActionOutput((short)3);
actions.add(action);
packetOut.setActions(actions);
return packetOut;
}
示例5: convertBCastToUcast
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
private OFPacketIn convertBCastToUcast(Ethernet eth,
OFPacketIn pi,
IDevice dst) {
byte[] dstMac = Ethernet.toByteArray(dst.getMACAddress());
eth.setDestinationMACAddress(dstMac);
byte[] serializedPacket = eth.serialize();
OFPacketIn fakePi =
((OFPacketIn) controllerProvider.getOFMessageFactory()
.getMessage(OFType.PACKET_IN))
.setInPort(pi.getInPort())
.setBufferId(OFPacketOut.BUFFER_ID_NONE)
.setReason(OFPacketInReason.NO_MATCH);
fakePi.setPacketData(serializedPacket);
fakePi.setTotalLength((short) serializedPacket.length);
fakePi.setLength((short)(OFPacketIn.MINIMUM_LENGTH +
serializedPacket.length));
return fakePi;
}
示例6: doDropFlow
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
@LogMessageDoc(level="ERROR",
message="Failure writing drop flow mod",
explanation="An I/O error occured while trying to write a " +
"drop flow mod to a switch",
recommendation=LogMessageDoc.CHECK_SWITCH)
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, IRoutingDecision decision, FloodlightContext cntx) {
// initialize match structure and populate it using the packet
OFMatch match = new OFMatch();
match.loadFromPacket(pi.getPacketData(), pi.getInPort());
if (decision.getWildcards() != null) {
match.setWildcards(decision.getWildcards());
}
// Create flow-mod based on packet-in and src-switch
OFFlowMod fm =
(OFFlowMod) floodlightProvider.getOFMessageFactory()
.getMessage(OFType.FLOW_MOD);
List<OFAction> actions = new ArrayList<OFAction>(); // Set no action to
// drop
long cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0);
fm.setCookie(cookie)
.setHardTimeout((short) 0)
.setIdleTimeout((short) 5)
.setBufferId(OFPacketOut.BUFFER_ID_NONE)
.setMatch(match)
.setActions(actions)
.setLengthU(OFFlowMod.MINIMUM_LENGTH); // +OFActionOutput.MINIMUM_LENGTH);
try {
if (log.isDebugEnabled()) {
log.debug("write drop flow-mod sw={} match={} flow-mod={}",
new Object[] { sw, match, fm });
}
messageDamper.write(sw, fm, cntx);
} catch (IOException e) {
log.error("Failure writing drop flow mod", e);
}
}
示例7: receive
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
OFPacketIn pi = (OFPacketIn) msg;
OFPacketOut po = (OFPacketOut) floodlightProvider.getOFMessageFactory()
.getMessage(OFType.PACKET_OUT);
po.setBufferId(pi.getBufferId())
.setInPort(pi.getInPort());
// set actions
OFActionOutput action = new OFActionOutput()
.setPort(OFPort.OFPP_FLOOD.getValue());
po.setActions(Collections.singletonList((OFAction)action));
po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);
// set data if is is included in the packetin
if (pi.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
byte[] packetData = pi.getPacketData();
po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
+ po.getActionsLength() + packetData.length));
po.setPacketData(packetData);
} else {
po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
+ po.getActionsLength()));
}
try {
sw.write(po, cntx);
} catch (IOException e) {
log.error("Failure writing PacketOut", e);
}
return Command.CONTINUE;
}
示例8: doDropFlow
import org.openflow.protocol.OFPacketOut; //导入依赖的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 fm =
(OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
OFMatch match = new OFMatch();
match.loadFromPacket(pi.getPacketData(), pi.getInPort());
List<OFAction> actions = new ArrayList<OFAction>(); // no actions = drop
long cookie = AppCookie.makeCookie(APP_ID, 0);
fm.setCookie(cookie)
.setIdleTimeout(ForwardingBase.FLOWMOD_DEFAULT_IDLE_TIMEOUT)
.setHardTimeout(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT)
.setBufferId(OFPacketOut.BUFFER_ID_NONE)
.setMatch(match)
.setActions(actions)
.setLengthU(OFFlowMod.MINIMUM_LENGTH);
// fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM);
try {
if (log.isTraceEnabled()) {
log.trace("write drop flow-mod srcSwitch={} match={} " +
"pi={} flow-mod={}",
new Object[] {sw, match, pi, fm});
}
sw.write(fm, cntx);
} catch (IOException e) {
log.error("Failure writing drop flow mod", e);
}
return;
}
示例9: initDefaultFlowMod
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
/**
* Sets defaults for an OFFlowMod
* @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 fm, String entryName) {
fm.setIdleTimeout((short) 0); // infinite
fm.setHardTimeout((short) 0); // infinite
fm.setBufferId(OFPacketOut.BUFFER_ID_NONE);
fm.setCommand((short) 0);
fm.setFlags((short) 0);
fm.setOutPort(OFPort.OFPP_NONE.getValue());
fm.setCookie(computeEntryCookie(fm, 0, entryName));
fm.setPriority(Short.MAX_VALUE);
}
示例10: testFloodNoBufferId
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
@Test
public void testFloodNoBufferId() throws Exception {
// build our expected flooded packetOut
OFPacketOut po = ((OFPacketOut) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT))
.setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())}))
.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
.setBufferId(-1)
.setInPort((short) 1)
.setPacketData(this.testPacketSerialized);
po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU()
+ this.testPacketSerialized.length);
// Mock up our expected behavior
IOFSwitch mockSwitch = createMock(IOFSwitch.class);
Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);
Capture<FloodlightContext> bc1 = new Capture<FloodlightContext>(CaptureType.ALL);
mockSwitch.write(capture(wc1), capture(bc1));
// Start recording the replay on the mocks
replay(mockSwitch);
// Get the listener and trigger the packet in
IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
OFType.PACKET_IN).get(0);
listener.receive(mockSwitch, this.packetIn,
parseAndAnnotate(this.packetIn));
// Verify the replay matched our expectations
verify(mockSwitch);
assertTrue(wc1.hasCaptured());
OFMessage m = wc1.getValue();
assertEquals(po, m);
}
示例11: testFloodBufferId
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
@Test
public void testFloodBufferId() throws Exception {
MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
this.packetIn.setBufferId(10);
// build our expected flooded packetOut
OFPacketOut po = ((OFPacketOut) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT))
.setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())}))
.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
.setBufferId(10)
.setInPort((short) 1);
po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU());
// Mock up our expected behavior
IOFSwitch mockSwitch = createMock(IOFSwitch.class);
Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);
Capture<FloodlightContext> bc1 = new Capture<FloodlightContext>(CaptureType.ALL);
mockSwitch.write(capture(wc1), capture(bc1));
// Start recording the replay on the mocks
replay(mockSwitch);
// Get the listener and trigger the packet in
IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
OFType.PACKET_IN).get(0);
listener.receive(mockSwitch, this.packetIn,
parseAndAnnotate(this.packetIn));
// Verify the replay matched our expectations
verify(mockSwitch);
assertTrue(wc1.hasCaptured());
OFMessage m = wc1.getValue();
assertEquals(po, m);
}
示例12: testFlood
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
@Test
public void testFlood() throws Exception {
// build our expected flooded packetOut
OFPacketOut po = new OFPacketOut()
.setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())}))
.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
.setBufferId(-1)
.setInPort((short)1)
.setPacketData(this.testPacketSerialized);
po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU()
+ this.testPacketSerialized.length);
// Mock up our expected behavior
IOFSwitch mockSwitch = createMock(IOFSwitch.class);
expect(mockSwitch.getStringId()).andReturn("00:11:22:33:44:55:66:77").anyTimes();
mockSwitch.write(po, null);
// Start recording the replay on the mocks
replay(mockSwitch);
// Get the listener and trigger the packet in
IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
OFType.PACKET_IN).get(0);
// Make sure it's the right listener
listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn));
// Verify the replay matched our expectations
short result = learningSwitch.getFromPortMap(mockSwitch, Ethernet.toLong(Ethernet.toMACAddress("00:44:33:22:11:00")), (short) 42).shortValue();
verify(mockSwitch);
// Verify the MAC table inside the switch
assertEquals(1, result);
}
示例13: DhcpDiscoveryRequestOFPacketIn
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
/**
* Generates a DHCP request OFPacketIn.
* @param hostMac The host MAC address of for the request.
* @return An OFPacketIn that contains a DHCP request packet.
*/
public static OFPacketIn DhcpDiscoveryRequestOFPacketIn(MACAddress hostMac) {
byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
return (((OFPacketIn)OFMessageFactory
.getMessage(OFType.PACKET_IN))
.setBufferId(OFPacketOut.BUFFER_ID_NONE)
.setInPort((short) 1)
.setPacketData(serializedPacket)
.setReason(OFPacketInReason.NO_MATCH)
.setTotalLength((short)serializedPacket.length));
}
示例14: receive
import org.openflow.protocol.OFPacketOut; //导入依赖的package包/类
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
OFPacketIn pi = (OFPacketIn) msg;
OFPacketOut po = (OFPacketOut) floodlightProvider.getOFMessageFactory()
.getMessage(OFType.PACKET_OUT);
po.setBufferId(pi.getBufferId())
.setInPort(pi.getInPort());
// set actions
OFActionOutput action = new OFActionOutput()
.setPort((short) OFPort.OFPP_FLOOD.getValue());
po.setActions(Collections.singletonList((OFAction)action));
po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);
// set data if is is included in the packetin
if (pi.getBufferId() == 0xffffffff) {
byte[] packetData = pi.getPacketData();
po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
+ po.getActionsLength() + packetData.length));
po.setPacketData(packetData);
} else {
po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
+ po.getActionsLength()));
}
try {
sw.write(po, cntx);
} catch (IOException e) {
log.error("Failure writing PacketOut", e);
}
return Command.CONTINUE;
}
示例15: doDropFlow
import org.openflow.protocol.OFPacketOut; //导入依赖的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 fm =
(OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
OFMatch match = new OFMatch();
match.loadFromPacket(pi.getPacketData(), pi.getInPort());
List<OFAction> actions = new ArrayList<OFAction>(); // no actions = drop
long cookie = AppCookie.makeCookie(APP_ID, 0);
fm.setCookie(cookie)
.setIdleTimeout(ForwardingBase.FLOWMOD_DEFAULT_IDLE_TIMEOUT)
.setHardTimeout(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT)
.setBufferId(OFPacketOut.BUFFER_ID_NONE)
.setMatch(match)
.setActions(actions)
.setLengthU(OFFlowMod.MINIMUM_LENGTH);
fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM);
try {
if (log.isTraceEnabled()) {
log.trace("write drop flow-mod srcSwitch={} match={} " +
"pi={} flow-mod={}",
new Object[] {sw, match, pi, fm});
}
sw.write(fm, cntx);
} catch (IOException e) {
log.error("Failure writing drop flow mod", e);
}
return;
}
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:45,代码来源:VirtualNetworkFilter.java