本文整理汇总了Java中net.floodlightcontroller.packet.IPv4.toIPv4Address方法的典型用法代码示例。如果您正苦于以下问题:Java IPv4.toIPv4Address方法的具体用法?Java IPv4.toIPv4Address怎么用?Java IPv4.toIPv4Address使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.floodlightcontroller.packet.IPv4
的用法示例。
在下文中一共展示了IPv4.toIPv4Address方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addMemberInTheTree
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
public boolean addMemberInTheTree(String IP, AttachmentPoint ap, long bamdwidth) {
Integer destIP = IPv4.toIPv4Address(IP);
IDevice destDevice = null;
destinationDevices.add(ap);
AddFlowsDirectedToDevice(ap, destDevice, bamdwidth);
return true;
// logger.info("---Bandwidth consuption log--");
// for (Entry<NodePortTuple, SwitchPortBandwidth> spb: mcObject.statisticsService.getBandwidthConsumption().entrySet()){
// logger.info("NodePortTuple " + spb.getKey().toString()
// +" SwitchPortBandwidth: BitsPerSecondRx = " + Long.toString(spb.getValue().getBitsPerSecondRx().getValue())
// + " BitsPerSecondTx" + Long.toString(spb.getValue().getBitsPerSecondTx().getValue())
// );
// }
//
// logger.info("---Bandwidth consuption log--");
}
示例2: testAll
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
private void testAll(OFActionTunnelDstIP tip) {
assertEquals(OFActionType.VENDOR, tip.getType());
assertEquals(2, tip.getSubtype());
assertEquals(16, tip.getLength());
assertEquals(0x005c16c7, tip.getVendor());
tip.setTunnelDstIP(24);
assertEquals(24, tip.getTunnelDstIP());
// Test wire format
int ip = IPv4.toIPv4Address("17.33.49.65");
tip.setTunnelDstIP(ip);
ChannelBuffer buf = ChannelBuffers.buffer(32);
tip.writeTo(buf);
ChannelBuffer buf2 = buf.copy();
assertEquals(16, buf.readableBytes());
byte fromBuffer[] = new byte[16];
buf.readBytes(fromBuffer);
assertArrayEquals(expectedWireFormat1, fromBuffer);
OFActionTunnelDstIP act2 = new OFActionTunnelDstIP();
act2.readFrom(buf2);
assertEquals(tip, act2);
}
示例3: parseCIDR
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
/**
* parse the given CIDR IP
*
* @return an array contains the CIDR prefix and mask bits
*
*/
public static int[] parseCIDR(String cidr) {
int ret[] = new int[2];
String[] parts = cidr.split("/");
if (parts.length == 1){
throw new IllegalArgumentException("CIDR mask bits must be specified.");
}
String cidrPrefix = parts[0].trim();
int cidrMaskBits = 0;
if (parts.length == 2) {
try {
cidrMaskBits = Integer.parseInt(parts[1].trim());
} catch (Exception e) {
throw new NumberFormatException("CIDR mask bits must be specified as a number(0 ~ 32).");
}
if (cidrMaskBits < 0 || cidrMaskBits > 32) {
throw new NumberFormatException("CIDR mask bits must be 0 <= value <= 32.");
}
}
ret[0] = IPv4.toIPv4Address(cidrPrefix);
ret[1] = cidrMaskBits;
return ret;
}
示例4: testContainIP
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
@Test
public void testContainIP(){
int[] cidr = IPAddressUtil.parseCIDR("10.0.0.0/8");
int ip = IPv4.toIPv4Address("10.0.0.1");
assertTrue(IPAddressUtil.containIP(cidr[0], cidr[1], ip));
}
示例5: getSrcNwAddr
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
/**
* Get sender IP address from packet if the packet is an ARP
* packet and if the source MAC address matches the ARP packets
* sender MAC address.
* @param eth
* @param dlAddr
* @return
*/
private int getSrcNwAddr(Ethernet eth, long dlAddr) {
if (eth.getPayload() instanceof ARP) {
ARP arp = (ARP) eth.getPayload();
if ((arp.getProtocolType() == ARP.PROTO_TYPE_IP) &&
(Ethernet.toLong(arp.getSenderHardwareAddress()) == dlAddr)) {
return IPv4.toIPv4Address(arp.getSenderProtocolAddress());
}
}
return 0;
}
示例6: learnDeviceFromArpResponseData
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
/**
* Learn device from ARP data in scenarios where the
* Ethernet source MAC is different from the sender hardware
* address in ARP data.
*/
protected void learnDeviceFromArpResponseData(Ethernet eth,
long swdpid,
int port) {
if (!(eth.getPayload() instanceof ARP)) return;
ARP arp = (ARP) eth.getPayload();
byte[] dlAddrArr = eth.getSourceMACAddress();
long dlAddr = Ethernet.toLong(dlAddrArr);
byte[] senderHardwareAddr = arp.getSenderHardwareAddress();
long senderAddr = Ethernet.toLong(senderHardwareAddr);
if (dlAddr == senderAddr) return;
// Ignore broadcast/multicast source
if ((senderHardwareAddr[0] & 0x1) != 0)
return;
// Ignore zero sender mac
if (senderAddr == 0)
return;
short vlan = eth.getVlanID();
int nwSrc = IPv4.toIPv4Address(arp.getSenderProtocolAddress());
Entity e = new Entity(senderAddr,
((vlan >= 0) ? vlan : null),
((nwSrc != 0) ? nwSrc : null),
swdpid,
port,
new Date());
learnDeviceByEntity(e);
}
示例7: testSimpleAllowRule
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
@Test
public void testSimpleAllowRule() throws Exception {
// enable firewall first
firewall.enableFirewall(true);
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.dl_type = Ethernet.TYPE_IPv4;
rule.wildcard_dl_type = false;
rule.nw_proto = IPv4.PROTOCOL_TCP;
rule.wildcard_nw_proto = false;
// source is IP 192.168.1.2
rule.nw_src_prefix = IPv4.toIPv4Address("192.168.1.2");
rule.wildcard_nw_src = false;
// dest is network 192.168.1.0/24
rule.nw_dst_prefix = IPv4.toIPv4Address("192.168.1.0");
rule.nw_dst_maskbits = 24;
rule.wildcard_nw_dst = false;
rule.priority = 1;
firewall.addRule(rule);
// simulate a packet-in events
this.setPacketIn(tcpPacketReply);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
IRoutingDecision decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(decision.getRoutingAction(), IRoutingDecision.RoutingAction.FORWARD_OR_FLOOD);
// clear decision
IRoutingDecision.rtStore.remove(cntx, IRoutingDecision.CONTEXT_DECISION);
this.setPacketIn(tcpPacket);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(decision.getRoutingAction(), IRoutingDecision.RoutingAction.DROP);
}
示例8: FM_redirect_ip
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
public FM_redirect_ip(FP_LibFloodlight lib, String id, String type, String event, String[] pars, String[] inputs) {
super(lib, id, type , event, pars, inputs, NUM_INPUT, NUM_OUTPUT);
redIP = IPv4.toIPv4Address(pars[0]);
}
示例9: parseIPv4
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
@Override
public int parseIPv4(String s){
return IPv4.toIPv4Address(s);
}
示例10: jsonToVip
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
protected LBVip jsonToVip(String json) throws IOException {
if (json==null) return null;
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
LBVip vip = new LBVip();
try {
jp = f.createParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n.equals("id")) {
vip.id = jp.getText();
continue;
}
if (n.equals("tenant_id")) {
vip.tenantId = jp.getText();
continue;
}
if (n.equals("name")) {
vip.name = jp.getText();
continue;
}
if (n.equals("network_id")) {
vip.netId = jp.getText();
continue;
}
if (n.equals("protocol")) {
String tmp = jp.getText();
if (tmp.equalsIgnoreCase("TCP")) {
vip.protocol = (byte) IpProtocol.TCP.getIpProtocolNumber();
} else if (tmp.equalsIgnoreCase("UDP")) {
vip.protocol = (byte) IpProtocol.UDP.getIpProtocolNumber();
} else if (tmp.equalsIgnoreCase("ICMP")) {
vip.protocol = (byte) IpProtocol.ICMP.getIpProtocolNumber();
}
continue;
}
if (n.equals("address")) {
vip.address = IPv4.toIPv4Address(jp.getText());
continue;
}
if (n.equals("port")) {
vip.port = Short.parseShort(jp.getText());
continue;
}
if (n.equals("pool_id")) {
vip.pools.add(jp.getText());
continue;
}
log.warn("Unrecognized field {} in " +
"parsing Vips",
jp.getText());
}
jp.close();
return vip;
}
示例11: jsonToMember
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
protected LBMember jsonToMember(String json) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
LBMember member = new LBMember();
try {
jp = f.createParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n.equals("id")) {
member.id = jp.getText();
continue;
} else
if (n.equals("address")) {
member.address = IPv4.toIPv4Address(jp.getText());
continue;
} else
if (n.equals("port")) {
member.port = Short.parseShort(jp.getText());
continue;
} else
if (n.equals("connection_limit")) {
member.connectionLimit = Integer.parseInt(jp.getText());
continue;
} else
if (n.equals("admin_state")) {
member.adminState = Short.parseShort(jp.getText());
continue;
} else
if (n.equals("status")) {
member.status = Short.parseShort(jp.getText());
continue;
} else
if (n.equals("pool_id")) {
member.poolId = jp.getText();
continue;
}
log.warn("Unrecognized field {} in " +
"parsing Members",
jp.getText());
}
jp.close();
return member;
}
示例12: jsonToVip
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
protected LBVip jsonToVip(String json) throws IOException {
if (json==null) return null;
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
LBVip vip = new LBVip();
try {
jp = f.createJsonParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n.equals("id")) {
vip.id = jp.getText();
continue;
}
if (n.equals("tenant_id")) {
vip.tenantId = jp.getText();
continue;
}
if (n.equals("name")) {
vip.name = jp.getText();
continue;
}
if (n.equals("network_id")) {
vip.netId = jp.getText();
continue;
}
if (n.equals("protocol")) {
String tmp = jp.getText();
if (tmp.equalsIgnoreCase("TCP")) {
vip.protocol = (byte) IpProtocol.TCP.getIpProtocolNumber();
} else if (tmp.equalsIgnoreCase("UDP")) {
vip.protocol = (byte) IpProtocol.UDP.getIpProtocolNumber();
} else if (tmp.equalsIgnoreCase("ICMP")) {
vip.protocol = (byte) IpProtocol.ICMP.getIpProtocolNumber();
}
continue;
}
if (n.equals("address")) {
vip.address = IPv4.toIPv4Address(jp.getText());
continue;
}
if (n.equals("port")) {
vip.port = Short.parseShort(jp.getText());
continue;
}
if (n.equals("pool_id")) {
vip.pools.add(jp.getText());
continue;
}
log.warn("Unrecognized field {} in " +
"parsing Vips",
jp.getText());
}
jp.close();
return vip;
}
示例13: jsonToMember
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
protected LBMember jsonToMember(String json) throws IOException {
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
LBMember member = new LBMember();
try {
jp = f.createJsonParser(json);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n.equals("id")) {
member.id = jp.getText();
continue;
} else
if (n.equals("address")) {
member.address = IPv4.toIPv4Address(jp.getText());
continue;
} else
if (n.equals("port")) {
member.port = Short.parseShort(jp.getText());
continue;
} else
if (n.equals("connection_limit")) {
member.connectionLimit = Integer.parseInt(jp.getText());
continue;
} else
if (n.equals("admin_state")) {
member.adminState = Short.parseShort(jp.getText());
continue;
} else
if (n.equals("status")) {
member.status = Short.parseShort(jp.getText());
continue;
} else
if (n.equals("pool_id")) {
member.poolId = jp.getText();
continue;
}
log.warn("Unrecognized field {} in " +
"parsing Members",
jp.getText());
}
jp.close();
return member;
}
示例14: processPacketIn
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
private net.floodlightcontroller.core.IListener.Command processPacketIn(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPacket pkt = eth.getPayload();
if (eth.isBroadcast() || eth.isMulticast()) {
// handle ARP for VIP
if (pkt instanceof ARP) {
// retrieve arp to determine target IP address
ARP arpRequest = (ARP) eth.getPayload();
int targetProtocolAddress = IPv4.toIPv4Address(arpRequest
.getTargetProtocolAddress());
if (vipIpToId.containsKey(targetProtocolAddress)) {
String vipId = vipIpToId.get(targetProtocolAddress);
vipProxyArpReply(sw, pi, cntx, vipId);
return Command.STOP;
}
}
} else {
// currently only load balance IPv4 packets - no-op for other traffic
if (pkt instanceof IPv4) {
IPv4 ip_pkt = (IPv4) pkt;
// If match Vip and port, check pool and choose member
int destIpAddress = ip_pkt.getDestinationAddress().getInt();
if (vipIpToId.containsKey(destIpAddress)){
IPClient client = new IPClient();
client.ipAddress = ip_pkt.getSourceAddress();
client.nw_proto = ip_pkt.getProtocol();
if (ip_pkt.getPayload() instanceof TCP) {
TCP tcp_pkt = (TCP) ip_pkt.getPayload();
client.srcPort = tcp_pkt.getSourcePort();
client.targetPort = tcp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof UDP) {
UDP udp_pkt = (UDP) ip_pkt.getPayload();
client.srcPort = udp_pkt.getSourcePort();
client.targetPort = udp_pkt.getDestinationPort();
}
if (ip_pkt.getPayload() instanceof ICMP) {
client.srcPort = TransportPort.of(8);
client.targetPort = TransportPort.of(0);
}
LBVip vip = vips.get(vipIpToId.get(destIpAddress));
LBPool pool = pools.get(vip.pickPool(client));
LBMember member = members.get(pool.pickMember(client));
// for chosen member, check device manager and find and push routes, in both directions
pushBidirectionalVipRoutes(sw, pi, cntx, client, member);
// packet out based on table rule
pushPacket(pkt, sw, pi.getBufferId(), (pi.getVersion().compareTo(OFVersion.OF_12) < 0) ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT), OFPort.TABLE,
cntx, true);
return Command.STOP;
}
}
}
// bypass non-load-balanced traffic for normal processing (forwarding)
return Command.CONTINUE;
}
示例15: testDeviceLearningFromArpResponseData
import net.floodlightcontroller.packet.IPv4; //导入方法依赖的package包/类
/**
* This test ensures the device manager learns the source device
* corresponding to the senderHardwareAddress and senderProtocolAddress
* in an ARP response whenever the senderHardwareAddress is different
* from the source MAC address of the Ethernet frame.
*
* @throws Exception
*/
@Test
public void testDeviceLearningFromArpResponseData() throws Exception {
ARP arp = (ARP)((Ethernet)this.testARPReplyPacket_2).getPayload();
MacAddress senderMac = MacAddress.of(arp.getSenderHardwareAddress());
MacAddress sourceMac =
((Ethernet)this.testARPReplyPacket_2)
.getSourceMACAddress();
Integer ipaddr = IPv4.toIPv4Address("192.168.1.1");
OFPacketIn packetIn = testARPReplyPacketIn_2;
// Mock up our expected behavior
ITopologyService mockTopology = createMock(ITopologyService.class);
deviceManager.topology = mockTopology;
mockTopologyForPacketInTests(mockTopology);
replay(mockTopology);
FloodlightContext cntx = new FloodlightContext();
Command cmd = dispatchPacketIn(1L, packetIn, cntx);
verify(mockTopology);
assertEquals(Command.CONTINUE, cmd);
// Verify the device for the sender HW address
Device senderDev = (Device)
deviceManager.findDevice(senderMac, VlanVid.ofVlan(5), null, null, null);
verifyDevice(senderDev, senderMac.getLong(), (short)5, ipaddr, 1L, 1);
Device result = null;
Iterator<? extends IDevice> dstiter =
deviceManager.queryDevices(null, null, IPv4Address.of(ipaddr),
null, null);
if (dstiter.hasNext()) {
result = (Device)dstiter.next();
}
assertFalse("There shouldn't be more than 1 device", dstiter.hasNext());
assertEquals(senderDev, result);
// Verify the device for the source MAC
Device srcDev = (Device)
deviceManager.findDevice(sourceMac, VlanVid.ofVlan(5), null, null, null);
// must NOT learn IP on this device
verifyDevice(srcDev, sourceMac.getLong(), (short)5, null, 1L, 1);
assertFalse("Device must differ", srcDev.equals(senderDev));
// Context is annotated with this device, not the device associated
// with ARP sender address
IDevice cntxSrcDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_SRC_DEVICE);
assertEquals(srcDev, cntxSrcDev);
assertEquals(2, deviceManager.getAllDevices().size());
}