本文整理汇总了Java中net.floodlightcontroller.packet.IPv4类的典型用法代码示例。如果您正苦于以下问题:Java IPv4类的具体用法?Java IPv4怎么用?Java IPv4使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IPv4类属于net.floodlightcontroller.packet包,在下文中一共展示了IPv4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
private VerificationPacket deserialize(Ethernet eth) throws Exception {
if (eth.getPayload() instanceof IPv4) {
IPv4 ip = (IPv4) eth.getPayload();
if (ip.getPayload() instanceof UDP) {
UDP udp = (UDP) ip.getPayload();
if ((udp.getSourcePort().getPort() == PathVerificationService.VERIFICATION_PACKET_UDP_PORT)
&& (udp.getDestinationPort()
.getPort() == PathVerificationService.VERIFICATION_PACKET_UDP_PORT)) {
return new VerificationPacket((Data) udp.getPayload());
}
}
}
throw new Exception("Ethernet packet was not a verification packet");
}
示例2: getSrcIP
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
@Override
public int getSrcIP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPv4Address srcIP;
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
srcIP = ipv4.getSourceAddress();
return srcIP.getInt();
}
else if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
srcIP = arp.getSenderProtocolAddress();
return srcIP.getInt();
}
//for other packets without source IP information
return 0;
}
示例3: getDstIP
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
@Override
public int getDstIP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPv4Address dstIP;
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
dstIP = ipv4.getDestinationAddress();
return dstIP.getInt();
}
else if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
dstIP = arp.getTargetProtocolAddress();
return dstIP.getInt();
}
//for other packets without destination IP information
return 0;
}
示例4: snoopDHCPClientName
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
/**
* Snoop and record client-provided host name from DHCP requests
* @param eth
* @param srcDevice
*/
private void snoopDHCPClientName(Ethernet eth, Device srcDevice) {
if (! (eth.getPayload() instanceof IPv4) )
return;
IPv4 ipv4 = (IPv4) eth.getPayload();
if (! (ipv4.getPayload() instanceof UDP) )
return;
UDP udp = (UDP) ipv4.getPayload();
if (!(udp.getPayload() instanceof DHCP))
return;
DHCP dhcp = (DHCP) udp.getPayload();
byte opcode = dhcp.getOpCode();
if (opcode == DHCP.OPCODE_REQUEST) {
DHCPOption dhcpOption = dhcp.getOption(
DHCPOptionCode.OptionCode_Hostname);
if (dhcpOption != null) {
cntDhcpClientNameSnooped.increment();
srcDevice.dhcpClientName = new String(dhcpOption.getData());
}
}
}
示例5: deviceAdded
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
@Override
public void deviceAdded(IDevice device) {
SwitchPort[] switchPort = device.getAttachmentPoints();
if (switchPort.length == 0) {
//Device manager does not yet know an attachment point for a device (Bug Fix)
return;
}
IPv4Address[] ips = device.getIPv4Addresses();
if (ips.length == 0) {
// A new no-ip device added
return;
}
String dpid = HexString.toHexString(switchPort[0].getSwitchDPID()
.getLong());
String ip = IPv4.fromIPv4Address(ips[0].getInt());
logger.debug("AP(dpid:{},ip:{}) is added", dpid, ip);
AP ap = new AP(ip, dpid);
apManager.addAP(ap);
processAPAdded(ap);
}
示例6: deviceIPV4AddrChanged
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
@Override
public void deviceIPV4AddrChanged(IDevice device) {
SwitchPort[] switchPort = device.getAttachmentPoints();
IPv4Address[] ips = device.getIPv4Addresses();
String dpid = HexString.toHexString(switchPort[0].getSwitchDPID()
.getLong());
String ip = null;
// some device may first appear with no IP address(default set to
// 0.0.0.0), ignore it
for (IPv4Address i : ips) {
if (i.getInt() != 0) {
ip = IPv4.fromIPv4Address(i.getInt());
break;
}
}
logger.debug("AP(dpid:{},ip:{}) is added", dpid, ip);
AP ap = new AP(ip, dpid);
apManager.addAP(ap);
processAPAdded(ap);
}
示例7: testDeviceIndex
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
@Test
public void testDeviceIndex() throws Exception {
EnumSet<IDeviceService.DeviceField> indexFields =
EnumSet.noneOf(IDeviceService.DeviceField.class);
indexFields.add(IDeviceService.DeviceField.IPv4);
indexFields.add(IDeviceService.DeviceField.VLAN);
deviceManager.addIndex(false, indexFields);
indexFields = EnumSet.noneOf(IDeviceService.DeviceField.class);
deviceManager.addIndex(false, indexFields);
ITopologyService mockTopology = createMock(ITopologyService.class);
deviceManager.topology = mockTopology;
expect(mockTopology.isAttachmentPointPort(DatapathId.of(anyLong()),
OFPort.of(anyShort()))).
andReturn(true).anyTimes();
expect(mockTopology.getOpenflowDomainId(DatapathId.of(EasyMock.anyLong()))).andReturn(DatapathId.of(1L)).anyTimes();
replay(mockTopology);
doTestDeviceQuery();
}
示例8: testDeviceClassIndex
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
@Test
public void testDeviceClassIndex() throws Exception {
EnumSet<IDeviceService.DeviceField> indexFields =
EnumSet.noneOf(IDeviceService.DeviceField.class);
indexFields.add(IDeviceService.DeviceField.IPv4);
indexFields.add(IDeviceService.DeviceField.VLAN);
deviceManager.addIndex(true, indexFields);
ITopologyService mockTopology = createMock(ITopologyService.class);
deviceManager.topology = mockTopology;
expect(mockTopology.isAttachmentPointPort(DatapathId.of(anyLong()),
OFPort.of(anyShort()))).
andReturn(true).anyTimes();
expect(mockTopology.getOpenflowDomainId(DatapathId.of(EasyMock.anyLong()))).andReturn(DatapathId.of(1L)).anyTimes();
replay(mockTopology);
doTestDeviceClassQuery();
}
示例9: createPacketIn
import net.floodlightcontroller.packet.IPv4; //导入依赖的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;
}
示例10: setObfuscatedHeader
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
public void setObfuscatedHeader(Ethernet eth) {
try {
//System.out.println(m.get(MatchField.ETH_SRC).getLong());
//System.out.println(m.get(MatchField.ETH_SRC));
encodeInBitSet(obfuscatedHeaderValue, ObfuscationPolicy.Field.MAC_SRC.getOffset(), ObfuscationPolicy.Field.MAC_SRC.getLength(), eth.getSourceMACAddress().getLong());
encodeInBitSet(obfuscatedHeaderValue, ObfuscationPolicy.Field.MAC_DST.getOffset(), ObfuscationPolicy.Field.MAC_DST.getLength(), eth.getDestinationMACAddress().getLong());
if (eth.getPayload() instanceof IPv4) {
IPv4 ip_pkt = (IPv4) eth.getPayload();
encodeInBitSet(obfuscatedHeaderValue, ObfuscationPolicy.Field.IP_SRC.getOffset(), ObfuscationPolicy.Field.IP_SRC.getLength(), ip_pkt.getSourceAddress().getInt());
encodeInBitSet(obfuscatedHeaderValue, ObfuscationPolicy.Field.IP_DST.getOffset(), ObfuscationPolicy.Field.IP_DST.getLength(), ip_pkt.getDestinationAddress().getInt());
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println(eth);
}
}
示例11: updateTopologyMappings
import net.floodlightcontroller.packet.IPv4; //导入依赖的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)));
}
}
}
}
示例12: receive
import net.floodlightcontroller.packet.IPv4; //导入依赖的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;
}
示例13: getDestEntityFromPacket
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
/**
* Get a (partial) entity for the destination from the packet.
* @param eth
* @return
*/
protected Entity getDestEntityFromPacket(Ethernet eth) {
MacAddress dlAddr = eth.getDestinationMACAddress();
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
IPv4Address nwDst = IPv4Address.NONE;
// Ignore broadcast/multicast destination
if (dlAddr.isBroadcast() || dlAddr.isMulticast())
return null;
// Ignore zero dest mac
if (dlAddr.getLong() == 0)
return null;
if (eth.getPayload() instanceof IPv4) {
IPv4 ipv4 = (IPv4) eth.getPayload();
nwDst = ipv4.getDestinationAddress();
}
return new Entity(dlAddr,
vlan,
nwDst,
null,
null,
null);
}
示例14: deviceAdded
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
/**
* listen for new device
*/
@Override
public void deviceAdded(IDevice device) {
SwitchPort[] switchPort = device.getAttachmentPoints();
IPv4Address[] ips = device.getIPv4Addresses();
if(ips.length == 0){
// A new no-ip device added
return;
}
String dpid = HexString.toHexString(switchPort[0].getSwitchDPID().getLong());
String ip = IPv4.fromIPv4Address(ips[0].getInt());
logger.info("New AP added. [dpid:" + dpid + " ip:" + ip + "]");
AP ap = new AP(ip,dpid);
apManager.addAP(ap);
processAPAdded(ap);
}
示例15: deviceIPV4AddrChanged
import net.floodlightcontroller.packet.IPv4; //导入依赖的package包/类
@Override
public void deviceIPV4AddrChanged(IDevice device) {
SwitchPort[] switchPort = device.getAttachmentPoints();
IPv4Address[] ips = device.getIPv4Addresses();
String dpid = HexString.toHexString(switchPort[0].getSwitchDPID().getLong());
String ip = null;
// some device may first appear with no IP address(default set to 0.0.0.0), ignore it
for(IPv4Address i : ips){
if(i.getInt() != 0){
ip = IPv4.fromIPv4Address(i.getInt());
break;
}
}
logger.info("New AP added. [dpid:" + dpid + " ip:" + ip + "]");
AP ap = new AP(ip, dpid);
apManager.addAP(ap);
processAPAdded(ap);
}