use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method timeTick.
/**
* Find lease-expired ipaddresses and pd prefixes.
* Removing host/route/fpm entries.
*/
public void timeTick() {
long currentTime = System.currentTimeMillis();
Collection<DhcpRecord> records = dhcpRelayStore.getDhcpRecords();
log.debug("timeTick called currenttime {} records num {} ", currentTime, records.size());
records.forEach(record -> {
boolean addrOrPdRemoved = false;
DHCP6.MsgType ip6Status = record.ip6Status().orElse(null);
if (ip6Status == null) {
log.debug("record is not valid v6 record.");
return;
}
if ((currentTime - record.getLastIp6Update()) > ((record.addrPrefTime() + getDhcp6PollInterval() / 2) * 1000)) {
// remove ipaddress from host/route table
IpAddress ip = record.ip6Address().orElse(null);
if (ip != null) {
if (record.directlyConnected()) {
providerService.removeIpFromHost(HostId.hostId(record.macAddress(), record.vlanId()), ip);
} else {
MacAddress gwMac = record.nextHop().orElse(null);
if (gwMac == null) {
log.warn("Can't find gateway mac address from record {} for ip6Addr", record);
return;
}
IpAddress nextHopIp = getFirstIpByHost(record.directlyConnected(), gwMac, record.vlanId());
Route route = new Route(Route.Source.DHCP, ip.toIpPrefix(), nextHopIp);
routeStore.removeRoute(route);
}
record.updateAddrPrefTime(0);
record.ip6Address(null);
addrOrPdRemoved = true;
dhcpRelayStore.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
log.warn("IP6 address is set to null. delta {} lastUpdate {} addrPrefTime {}", (currentTime - record.getLastIp6Update()), record.getLastIp6Update(), record.addrPrefTime());
}
}
if ((currentTime - record.getLastPdUpdate()) > ((record.pdPrefTime() + getDhcp6PollInterval() / 2) * 1000)) {
// remove PD from route/fpm table
IpPrefix pdIpPrefix = record.pdPrefix().orElse(null);
if (pdIpPrefix != null) {
if (record.directlyConnected()) {
providerService.removeIpFromHost(HostId.hostId(record.macAddress(), record.vlanId()), pdIpPrefix.address().getIp6Address());
} else {
MacAddress gwMac = record.nextHop().orElse(null);
if (gwMac == null) {
log.warn("Can't find gateway mac address from record {} for PD prefix", record);
return;
}
IpAddress nextHopIp = getFirstIpByHost(record.directlyConnected(), gwMac, record.vlanId());
Route route = new Route(Route.Source.DHCP, pdIpPrefix, nextHopIp);
routeStore.removeRoute(route);
if (this.dhcpFpmEnabled) {
dhcpFpmPrefixStore.removeFpmRecord(pdIpPrefix);
}
}
record.updatePdPrefTime(0);
record.pdPrefix(null);
addrOrPdRemoved = true;
dhcpRelayStore.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
log.warn("PD prefix is set to null.delta {} pdPrefTime {}", (currentTime - record.getLastPdUpdate()), record.pdPrefTime());
}
}
if (addrOrPdRemoved && !record.ip6Address().isPresent() && !record.pdPrefix().isPresent()) {
log.warn("ip6Status {} IP6 address and IP6 PD both are null. Remove record.", ip6Status);
dhcpRelayStore.removeDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()));
}
});
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class OpenstackTroubleshootManager method constructNorthSouthIcmpPacket.
/**
* Constructs a north-south ICMP packet with the given destination IP/MAC.
*
* @param dstPort destination instance port
* @param icmpId ICMP identifier
* @param icmpSeq ICMP sequence number
* @return an ethernet frame which contains ICMP payload
*/
private Ethernet constructNorthSouthIcmpPacket(InstancePort dstPort, short icmpId, short icmpSeq) {
IpAddress localIp = clusterService.getLocalNode().ip();
IpAddress fip = instancePortService.floatingIp(dstPort.portId());
if (fip != null) {
return constructIcmpPacket(localIp, fip, LOCAL_MAC, dstPort.macAddress(), icmpId, icmpSeq);
} else {
return null;
}
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class FpmAcceptRoutesCodec method decode.
@Override
public FpmPeerAcceptRoutes decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
IpAddress address = IpAddress.valueOf(json.path(PEER_ADDRESS).asText());
int port = Integer.parseInt(json.path(PEER_PORT).asText());
boolean isAcceptRoutes = Boolean.valueOf(json.path(ACCEPT_ROUTES).asText());
FpmPeer peer = new FpmPeer(address, port);
FpmPeerAcceptRoutes updatedPeer = new FpmPeerAcceptRoutes(peer, isAcceptRoutes);
return updatedPeer;
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class FpmWebResource method getFpmConnectionsJsonOutput.
private ObjectNode getFpmConnectionsJsonOutput() {
FpmInfoService fpmService = get(FpmInfoService.class);
ObjectNode node = mapper().createObjectNode();
ArrayNode connectionArray = mapper().createArrayNode();
Map<FpmPeer, FpmPeerInfo> fpmPeers = fpmService.peers();
fpmPeers.entrySet().stream().sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address()).thenComparing(e -> e.getKey().port())).map(Map.Entry::getValue).forEach(fpmPeerInfo -> connectionArray.add((new FpmCodec()).encode(fpmPeerInfo, this)));
node.put("fpm-connections", connectionArray);
return node;
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class InterfaceIpAddress method computeBroadcastAddress.
/**
* Compute the IP broadcast address.
*
* @param ipAddress base IP address
* @param subnetAddress subnet specification
* @return the IP broadcast address
*/
public static IpAddress computeBroadcastAddress(IpAddress ipAddress, IpPrefix subnetAddress) {
if (ipAddress.isIp6()) {
return null;
} else {
IpAddress maskedIP = IpAddress.makeMaskedAddress(ipAddress, subnetAddress.prefixLength());
int ipB = maskedIP.getIp4Address().toInt() | ((1 << (32 - subnetAddress.prefixLength())) - 1);
return IpAddress.valueOf(ipB);
}
}
Aggregations