本文整理汇总了Java中org.projectfloodlight.openflow.types.IPv4Address类的典型用法代码示例。如果您正苦于以下问题:Java IPv4Address类的具体用法?Java IPv4Address怎么用?Java IPv4Address使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IPv4Address类属于org.projectfloodlight.openflow.types包,在下文中一共展示了IPv4Address类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetSwitchPortVlanId
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
@Test
public void testGetSwitchPortVlanId() {
Entity entity1 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(1), IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(10L), OFPort.of(1), new Date());
Entity entity2 = new Entity(MacAddress.of(1L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(10L), OFPort.of(1), new Date());
Entity entity3 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(3), IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(1L), OFPort.of(1), new Date());
Entity entity4 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(42), IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(1L), OFPort.of(1), new Date());
Entity[] entities = new Entity[] { entity1, entity2,
entity3, entity4
};
Device d = new Device(null,1L, null, null, null,
Arrays.asList(entities), null);
SwitchPort swp1x1 = new SwitchPort(DatapathId.of(1L), OFPort.of(1));
SwitchPort swp1x2 = new SwitchPort(DatapathId.of(1L), OFPort.of(2));
SwitchPort swp2x1 = new SwitchPort(DatapathId.of(2L), OFPort.of(1));
SwitchPort swp10x1 = new SwitchPort(DatapathId.of(10L), OFPort.of(1));
assertArrayEquals(new VlanVid[] { VlanVid.ZERO, VlanVid.ofVlan(1)},
d.getSwitchPortVlanIds(swp10x1));
assertArrayEquals(new VlanVid[] { VlanVid.ofVlan(3), VlanVid.ofVlan(42)},
d.getSwitchPortVlanIds(swp1x1));
assertArrayEquals(new VlanVid[0],
d.getSwitchPortVlanIds(swp1x2));
assertArrayEquals(new VlanVid[0],
d.getSwitchPortVlanIds(swp2x1));
}
示例2: deviceAdded
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的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);
}
示例3: joinGroup
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
public boolean joinGroup(IPv4Address groupAddr, IPv4Address hostAddr, MacAddress hostMac, DatapathId dpid, OFPort port) {
MulticastGroup group = getGroup(groupAddr.toString());
if (group == null) {
log.error("Multicast group " + groupAddr + " does not exist");
return false;
}
// if not already in group
if (!checkHost(groupAddr.toString(), hostAddr.toString())) {
group.addHost(hostAddr, hostMac, dpid, port);
log.info("Adding a new host to multicast group: " +
hostAddr + " -> " + groupAddr +
" | dpid:port -> " + dpid.toString() + ":" + port.toString());
return true;
}
log.warn("Host " + hostAddr + " already part of group " + groupAddr);
return false;
}
示例4: getSrcIP
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的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;
}
示例5: getDstIP
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的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;
}
示例6: sendArpReply
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
private void sendArpReply(MacAddress senderMac, IPv4Address senderIp, MacAddress targetMac, IPv4Address targetIp, IOFSwitch sw, OFPort port) {
IPacket arpReply = new Ethernet()
.setSourceMACAddress(senderMac)
.setDestinationMACAddress(targetMac)
.setEtherType(EthType.ARP)
.setPayload(
new ARP()
.setHardwareType(ARP.HW_TYPE_ETHERNET)
.setProtocolType(ARP.PROTO_TYPE_IP)
.setHardwareAddressLength((byte) 6)
.setProtocolAddressLength((byte) 4)
.setOpCode(ARP.OP_REPLY)
.setSenderHardwareAddress(senderMac.getBytes())
.setSenderProtocolAddress(senderIp.getBytes())
.setTargetHardwareAddress(targetMac.getBytes())
.setTargetProtocolAddress(targetIp.getBytes()));
pushPacket(arpReply, sw, OFBufferId.NO_BUFFER, OFPort.ANY, port);
}
示例7: verifyDevice
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
/**
* Verify that the given device exactly matches the given fields. E.g.,
* if ip is not null we expect the device to have exactly one IP address.
* swId and port are the attachment point port.
* Vlan and ip are optional all other fields must be specified.
* @return
*/
private static void verifyDevice(IDevice d, MacAddress mac, VlanVid vlan, IPv4Address ipv4,
IPv6Address ipv6, DatapathId swId, OFPort port) {
assertNotNull(d);
if (!mac.equals(MacAddress.NONE)) {
assertEquals(mac, d.getMACAddress());
}
if (vlan != null) {
assertArrayEquals(new VlanVid[] { vlan }, d.getVlanId());
}
if (!ipv4.equals(IPv4Address.NONE)) {
assertArrayEquals(new IPv4Address[] { ipv4 }, d.getIPv4Addresses());
}
if (!ipv6.equals(IPv6Address.NONE)) {
assertArrayEquals(new IPv6Address[] { ipv6 }, d.getIPv6Addresses());
}
if (!swId.equals(DatapathId.NONE) && !port.equals(OFPort.ZERO)) {
SwitchPort expectedAp = new SwitchPort(swId, port);
assertArrayEquals(new SwitchPort[] { expectedAp }, d.getAttachmentPoints());
}
}
示例8: setUp
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
e1a = new Entity(MacAddress.of(1L), VlanVid.ofVlan(1), IPv4Address.of(1), DatapathId.of(1L), OFPort.of(1), new Date());
e1b = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), IPv4Address.of(1), DatapathId.of(1L), OFPort.of(1), new Date());
List<Entity> d1Entities = new ArrayList<Entity>(2);
d1Entities.add(e1a);
d1Entities.add(e1b);
d1 = new Device(null, Long.valueOf(1), null, null, null,
d1Entities, null);
// e2 and e2 alt match in MAC and VLAN
e2 = new Entity(MacAddress.of(2L), VlanVid.ofVlan(2), IPv4Address.of(2), DatapathId.of(2L), OFPort.of(2), new Date());
e2alt = new Entity(MacAddress.of(2L), VlanVid.ofVlan(2), null, null, null, null);
// IP is null
e3 = new Entity(MacAddress.of(3L), VlanVid.ofVlan(3), null, DatapathId.of(3L), OFPort.of(3), new Date());
// IP and switch and port are null
e4 = new Entity(MacAddress.of(4L), VlanVid.ofVlan(4), null, null, null, new Date());
}
示例9: init
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
@Override
public void init(FloodlightModuleContext context)
throws FloodlightModuleException {
floodlightProviderService = context.getServiceImpl(IFloodlightProviderService.class);
restApiService = context.getServiceImpl(IRestApiService.class);
deviceService = context.getServiceImpl(IDeviceService.class);
vNetsByGuid = new ConcurrentHashMap<String, VirtualNetwork>();
nameToGuid = new ConcurrentHashMap<String, String>();
guidToGateway = new ConcurrentHashMap<String, IPv4Address>();
gatewayToGuid = new ConcurrentHashMap<IPv4Address, Set<String>>();
macToGuid = new ConcurrentHashMap<MacAddress, String>();
portToMac = new ConcurrentHashMap<String, MacAddress>();
macToGateway = new ConcurrentHashMap<MacAddress, IPv4Address>();
deviceListener = new DeviceListenerImpl();
}
示例10: getEntityKeys
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
private EnumSet<DeviceField> getEntityKeys(MacAddress macAddress,
VlanVid vlan,
IPv4Address ipv4Address,
DatapathId switchDPID,
OFPort switchPort) {
// FIXME: vlan==null is a valid search. Need to handle this
// case correctly. Note that the code will still work correctly.
// But we might do a full device search instead of using an index.
EnumSet<DeviceField> keys = EnumSet.noneOf(DeviceField.class);
if (macAddress != null) keys.add(DeviceField.MAC);
if (vlan != null) keys.add(DeviceField.VLAN);
if (ipv4Address != null) keys.add(DeviceField.IPV4);
if (switchDPID != null) keys.add(DeviceField.SWITCH);
if (switchPort != null) keys.add(DeviceField.PORT);
return keys;
}
示例11: deviceIPV4AddrChanged
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的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);
}
示例12: removeIPv4FromDHCPPool
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
/**
* Completely removes the DHCPBinding object with IP address {@code byte[]} ip from the DHCPPool
* @param {@code byte[]} ip: The IP address to remove from the pool. This address will not be available
* for lease after removal.
* @return none
*/
public void removeIPv4FromDHCPPool(IPv4Address ip) {
if (ip == null || getDHCPbindingFromIPv4(ip) == null) return;
if (ip.equals(STARTING_ADDRESS)) {
DHCPBinding lowest = null;
// Locate the lowest address (other than ip), which will be the new starting address
for (DHCPBinding binding : DHCP_POOL) {
if (lowest == null) {
lowest = binding;
} else if (binding.getIPv4Address().getInt() < lowest.getIPv4Address().getInt()
&& !binding.getIPv4Address().equals(ip))
{
lowest = binding;
}
}
// lowest is new starting address
STARTING_ADDRESS = lowest.getIPv4Address();
}
DHCP_POOL.remove(this.getDHCPbindingFromIPv4(ip));
this.setPoolSize(this.getPoolSize() - 1);
this.setPoolAvailability(this.getPoolAvailability() - 1);
if (this.getPoolAvailability() == 0) this.setPoolFull(true);
}
示例13: testLastSeen
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
@Test
public void testLastSeen() throws Exception {
Calendar c = Calendar.getInstance();
Date d1 = c.getTime();
Entity entity1 = new Entity(MacAddress.of(1L), null, null, null, null, d1);
c.add(Calendar.SECOND, 1);
Entity entity2 = new Entity(MacAddress.of(1L), null, IPv4Address.of(1), null, null, c.getTime());
IDevice d = deviceManager.learnDeviceByEntity(entity2);
assertEquals(c.getTime(), d.getLastSeen());
d = deviceManager.learnDeviceByEntity(entity1);
assertEquals(c.getTime(), d.getLastSeen());
deviceManager.startUp(null);
d = deviceManager.learnDeviceByEntity(entity1);
assertEquals(d1, d.getLastSeen());
d = deviceManager.learnDeviceByEntity(entity2);
assertEquals(c.getTime(), d.getLastSeen());
}
示例14: handleARP
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
private void handleARP(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if (! (eth.getPayload() instanceof ARP)) // not an ARP packet
return;
ARP arpRequest = (ARP) eth.getPayload();
if (arpRequest.getOpCode() == ARP.OP_REPLY) { // is a reply
oTopologyManager.updateTopologyMappings(sw, pi, cntx);
for (ARP pendingArpRequest : arpRequestBuffer.getPendingRequests(IPv4Address.of(arpRequest.getSenderProtocolAddress()))) {
if (oTopologyManager.knowSwitchForIp(IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()))) {
SwitchHostInfo dstSwitchPort = oTopologyManager.getSwitchForIp(IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()));
sendArpReply(MacAddress.of(arpRequest.getSenderHardwareAddress()), IPv4Address.of(arpRequest.getSenderProtocolAddress()), MacAddress.of(pendingArpRequest.getSenderHardwareAddress()), IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()), dstSwitchPort.getSwitch(), dstSwitchPort.getPort());
arpRequestBuffer.removeRequest(pendingArpRequest);
}
else
log.warn("answering pending ARP request failed because dst switch/port is not known. {}",pendingArpRequest);
}
}
else { // is a request
if (IPv4Address.of(arpRequest.getSenderProtocolAddress()).toString().contentEquals("10.0.0.111")) // ignore crafted requests from switches
return;
if (oTopologyManager.knowMacForIp(IPv4Address.of(arpRequest.getTargetProtocolAddress()))) {
MacAddress senderMac = oTopologyManager.getMacForIp(IPv4Address.of(arpRequest.getTargetProtocolAddress()));
sendArpReply(senderMac, IPv4Address.of(arpRequest.getTargetProtocolAddress()), MacAddress.of(arpRequest.getSenderHardwareAddress()), IPv4Address.of(arpRequest.getSenderProtocolAddress()), sw, pi.getMatch().get(MatchField.IN_PORT));
}
else {
arpRequestBuffer.addRequest(arpRequest);
for (DatapathId swi : switchService.getAllSwitchDpids())
floodArpRequest(switchService.getSwitch(swi),IPv4Address.of(arpRequest.getTargetProtocolAddress()));
}
}
}
示例15: getIPv4Addresses
import org.projectfloodlight.openflow.types.IPv4Address; //导入依赖的package包/类
@Override
public IPv4Address[] getIPv4Addresses() {
// XXX - TODO we can cache this result. Let's find out if this
// is really a performance bottleneck first though.
TreeSet<IPv4Address> vals = new TreeSet<IPv4Address>();
for (Entity e : entities) {
if (e.getIpv4Address() == null) continue;
// We have an IP address only if among the devices within the class
// we have the most recent entity with that IP.
boolean validIP = true;
Iterator<Device> devices =
deviceManager.queryClassByEntity(entityClass, ipv4Fields, e);
while (devices.hasNext()) {
Device d = devices.next();
if (deviceKey.equals(d.getDeviceKey()))
continue;
for (Entity se : d.entities) {
if (se.getIpv4Address() != null &&
se.getIpv4Address().equals(e.getIpv4Address()) &&
se.getLastSeenTimestamp() != null &&
0 < se.getLastSeenTimestamp().
compareTo(e.getLastSeenTimestamp())) {
validIP = false;
break;
}
}
if (!validIP)
break;
}
if (validIP)
vals.add(e.getIpv4Address());
}
return vals.toArray(new IPv4Address[vals.size()]);
}