本文整理汇总了Java中org.projectfloodlight.openflow.protocol.OFPacketIn类的典型用法代码示例。如果您正苦于以下问题:Java OFPacketIn类的具体用法?Java OFPacketIn怎么用?Java OFPacketIn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OFPacketIn类属于org.projectfloodlight.openflow.protocol包,在下文中一共展示了OFPacketIn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DhcpDiscoveryRequestOFPacketIn
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的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(IOFSwitch sw,
MacAddress hostMac) {
byte[] serializedPacket = DhcpDiscoveryRequestEthernet(hostMac).serialize();
OFFactory factory = sw.getOFFactory();
OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
if (factory.getVersion() == OFVersion.OF_10) {
packetInBuilder
.setInPort(OFPort.of(1))
.setData(serializedPacket)
.setReason(OFPacketInReason.NO_MATCH);
} else {
packetInBuilder
.setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
.setData(serializedPacket)
.setReason(OFPacketInReason.NO_MATCH);
}
return packetInBuilder.build();
}
示例2: dispatchMessage
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
public void dispatchMessage(IOFSwitch sw, OFMessage msg, FloodlightContext bc) {
List<IOFMessageListener> theListeners = listeners.get(msg.getType()).getOrderedListeners();
if (theListeners != null) {
Command result = Command.CONTINUE;
Iterator<IOFMessageListener> it = theListeners.iterator();
if (OFType.PACKET_IN.equals(msg.getType())) {
OFPacketIn pi = (OFPacketIn)msg;
Ethernet eth = new Ethernet();
eth.deserialize(pi.getData(), 0, pi.getData().length);
IFloodlightProviderService.bcStore.put(bc,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
}
while (it.hasNext() && !Command.STOP.equals(result)) {
result = it.next().receive(sw, msg, bc);
}
}
// paag
for (IControllerCompletionListener listener:completionListeners)
listener.onMessageConsumed(sw, msg, bc);
}
示例3: createHubPacketOut
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的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();
}
示例4: createPacketIn
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
private OFPacketIn createPacketIn(String srcMAC, String dstMAC,
String srcIp, String dstIp, short vlan) {
IPacket testPacket = new Ethernet()
.setDestinationMACAddress(dstMAC)
.setSourceMACAddress(srcMAC)
.setVlanID(vlan)
.setEtherType(EthType.IPv4)
.setPayload(
new IPv4()
.setTtl((byte) 128)
.setSourceAddress(srcIp)
.setDestinationAddress(dstIp)
.setPayload(new UDP()
.setSourcePort((short) 5000)
.setDestinationPort((short) 5001)
.setPayload(new Data(new byte[] {0x01}))));
byte[] testPacketSerialized = testPacket.serialize();
OFPacketIn pi;
// build out input packet
pi = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
.setBufferId(OFBufferId.NO_BUFFER)
.setData(testPacketSerialized)
.setReason(OFPacketInReason.NO_MATCH)
.build();
return pi;
}
示例5: dropFilter
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
/**
* If the packet-in switch port is disabled for all data traffic, then
* the packet will be dropped. Otherwise, the packet will follow the
* normal processing chain.
* @param sw
* @param pi
* @param cntx
* @return
*/
protected Command dropFilter(DatapathId sw, OFPacketIn pi,
FloodlightContext cntx) {
Command result = Command.CONTINUE;
OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));
// If the input port is not allowed for data traffic, drop everything.
// BDDP packets will not reach this stage.
if (isAllowed(sw, inPort) == false) {
if (log.isTraceEnabled()) {
log.trace("Ignoring packet because of topology " +
"restriction on switch={}, port={}", sw.getLong(), inPort.getPortNumber());
result = Command.STOP;
}
}
return result;
}
示例6: processPacketInMessage
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
protected Command processPacketInMessage(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
// get the packet-in switch.
Ethernet eth =
IFloodlightProviderService.bcStore.
get(cntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if (eth.getPayload() instanceof BSN) {
BSN bsn = (BSN) eth.getPayload();
if (bsn == null) return Command.STOP;
if (bsn.getPayload() == null) return Command.STOP;
// It could be a packet other than BSN LLDP, therefore
// continue with the regular processing.
if (bsn.getPayload() instanceof LLDP == false)
return Command.CONTINUE;
doFloodBDDP(sw.getId(), pi, cntx);
return Command.STOP;
} else {
return dropFilter(sw.getId(), pi, cntx);
}
}
示例7: receive
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
@Override
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
if (!this.enabled) {
return Command.CONTINUE;
}
switch (msg.getType()) {
case PACKET_IN:
IRoutingDecision decision = null;
if (cntx != null) {
decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
return this.processPacketInMessage(sw, (OFPacketIn) msg, decision, cntx);
}
break;
default:
break;
}
return Command.CONTINUE;
}
示例8: dispatchMessage
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
public void dispatchMessage(IOFSwitch sw, OFMessage msg, FloodlightContext bc) {
List<IOFMessageListener> theListeners = listeners.get(msg.getType()).getOrderedListeners();
if (theListeners != null) {
Command result = Command.CONTINUE;
Iterator<IOFMessageListener> it = theListeners.iterator();
if (OFType.PACKET_IN.equals(msg.getType())) {
OFPacketIn pi = (OFPacketIn)msg;
Ethernet eth = new Ethernet();
eth.deserialize(pi.getData(), 0, pi.getData().length);
IFloodlightProviderService.bcStore.put(bc,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
}
while (it.hasNext() && !Command.STOP.equals(result)) {
result = it.next().receive(sw, msg, bc);
}
}
}
示例9: testMessageDispatchMaster
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
/**
* Test dispatch of messages while in MASTER role
*/
@Test
public void testMessageDispatchMaster() throws Exception {
testInitialMoveToMasterWithRole();
// Send packet in. expect dispatch
OFPacketIn pi = factory.buildPacketIn()
.setReason(OFPacketInReason.NO_MATCH)
.build();
reset(switchManager);
switchManager.handleMessage(sw, pi, null);
expectLastCall().once();
replay(switchManager);
switchHandler.processOFMessage(pi);
// TODO: many more to go
}
示例10: updateTopologyMappings
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
public void updateTopologyMappings(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if (eth.getPayload() instanceof IPv4) {
IPv4 ip_pkt = (IPv4) eth.getPayload();
if (ip_pkt.getSourceAddress().getInt() > 0) {
IpToMac.put(ip_pkt.getSourceAddress(), eth.getSourceMACAddress());
IpToSwitch.put(ip_pkt.getSourceAddress(),new SwitchHostInfo(sw,pi.getMatch().get(MatchField.IN_PORT)));
}
}
else if (eth.getPayload() instanceof ARP) {
ARP arp_pkt = (ARP) eth.getPayload();
if (IPv4Address.of(arp_pkt.getSenderProtocolAddress()).getInt() > 0) {
if (!IPv4Address.of(arp_pkt.getSenderProtocolAddress()).toString().contentEquals("10.0.0.111")) {// ignore crafted requests from switches
IpToMac.put(IPv4Address.of(arp_pkt.getSenderProtocolAddress()), eth.getSourceMACAddress());
IpToSwitch.put(IPv4Address.of(arp_pkt.getSenderProtocolAddress()),new SwitchHostInfo(sw,pi.getMatch().get(MatchField.IN_PORT)));
}
}
}
}
示例11: receive
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
@Override
public net.floodlightcontroller.core.IListener.Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
oTopologyManager.updateTopologyMappings(sw, (OFPacketIn) msg, cntx);
//log.debug("receive {}",eth);
if ((eth.getPayload() instanceof ARP)) {
handleARP(sw, (OFPacketIn) msg, cntx);
}
else if (eth.getPayload() instanceof IPv4) {
handleIP(sw, (OFPacketIn) msg, cntx);
}
else {
//handleCbench(sw, (OFPacketIn) msg, cntx);
//log.warn("could not handle packet {}",eth.toString());
}
return Command.CONTINUE;
}
示例12: writePacketOutForPacketIn
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的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());
}
示例13: testMessageDispatchMaster
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
/**
* Test dispatch of messages while in MASTER role
*/
@Test
public void testMessageDispatchMaster() throws Exception {
testInitialMoveToMasterWithRole();
// Send packet in. expect dispatch
OFPacketIn pi = factory.buildPacketIn()
.setReason(OFPacketInReason.NO_MATCH)
.build();
reset(switchManager);
switchManager.handleMessage(sw, pi, null);
expectLastCall().once();
replay(switchManager);
switchHandler.processOFMessage(pi);
// TODO: many more to go
}
示例14: processOFPacketIn
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
@Override
@LogMessageDoc(level="WARN",
message="Received PacketIn from switch {} while" +
"being slave. Reasserting slave role.",
explanation="The switch has receive a PacketIn despite being " +
"in slave role indicating inconsistent controller roles",
recommendation="This situation can occurs transiently during role" +
" changes. If, however, the condition persists or happens" +
" frequently this indicates a role inconsistency. " +
LogMessageDoc.CHECK_CONTROLLER )
void processOFPacketIn(OFPacketIn m) {
// we don't expect packetIn while slave, reassert we are slave
switchManagerCounters.packetInWhileSwitchIsSlave.increment();
log.warn("Received PacketIn from switch {} while" +
"being slave. Reasserting slave role.", sw);
reassertRole(OFControllerRole.ROLE_SLAVE);
}
示例15: testDhcp
import org.projectfloodlight.openflow.protocol.OFPacketIn; //导入依赖的package包/类
@Test
public void testDhcp() {
IOFMessageListener listener = getVirtualNetworkListener();
Ethernet dhcpPacket = PacketFactory.DhcpDiscoveryRequestEthernet(mac1);
OFPacketIn dhcpPacketOf = PacketFactory.DhcpDiscoveryRequestOFPacketIn(sw1, mac1);
cntx = new FloodlightContext();
IFloodlightProviderService.bcStore.put(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
dhcpPacket);
Command ret = listener.receive(sw1, dhcpPacketOf, cntx);
assertTrue(ret == Command.CONTINUE);
}