use of org.onosproject.dhcprelay.store.DhcpRecord in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method setPotentialNextHopForIp6InRelayStore.
private void setPotentialNextHopForIp6InRelayStore(Ip6Address clientAddress, VlanId vlanId, MacAddress nh) {
DhcpRecord dr = getDhcpRelayRecordFor(clientAddress);
if (dr != null) {
dr.nextHopTemp(nh);
log.debug("LQ6 potential NH mac " + nh.toString() + " UPDATED in RelayRecord client " + clientAddress);
} else {
log.warn("LQ6 potential NH mac" + nh.toString() + " NOT FOUND in RelayRecord for client - LQ rejected" + clientAddress);
}
}
use of org.onosproject.dhcprelay.store.DhcpRecord in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method getDhcpRelayRecordFor.
public DhcpRecord getDhcpRelayRecordFor(Ip6Address clientAddress) {
Collection<DhcpRecord> records = dhcpRelayStore.getDhcpRecords();
DhcpRecord dr = null;
for (DhcpRecord e : records) {
if (e.ip6Address().isPresent()) {
if (e.ip6Address().get().equals(clientAddress)) {
dr = e;
break;
}
}
}
return dr;
}
use of org.onosproject.dhcprelay.store.DhcpRecord in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method removeHostOrRoute.
/**
* remove host or route and update dhcp relay record attributes.
*
* @param directConnFlag flag to show that packet is from directly connected client
* @param location client side connect point
* @param dhcp6Packet the dhcp6 payload
* @param clientPacket client's ethernet packet
* @param clientIpv6 client's Ipv6 packet
* @param clientInterface client interfaces
*/
private void removeHostOrRoute(boolean directConnFlag, ConnectPoint location, DHCP6 dhcp6Packet, Ethernet clientPacket, IPv6 clientIpv6, Interface clientInterface) {
log.debug("removeHostOrRoute enters {}", dhcp6Packet);
VlanId vlanId = clientInterface.vlan();
// could be gw or host
MacAddress srcMac = clientPacket.getSourceMAC();
MacAddress leafClientMac;
byte leafMsgType;
log.debug("client mac {} client vlan {}", HexString.toHexString(srcMac.toBytes(), ":"), vlanId);
Dhcp6ClientIdOption clientIdOption = Dhcp6HandlerUtil.extractClientId(directConnFlag, dhcp6Packet);
if (clientIdOption != null) {
if ((clientIdOption.getDuid().getDuidType() == Dhcp6Duid.DuidType.DUID_LLT) || (clientIdOption.getDuid().getDuidType() == Dhcp6Duid.DuidType.DUID_LL)) {
leafClientMac = MacAddress.valueOf(clientIdOption.getDuid().getLinkLayerAddress());
} else {
log.warn("Link-Layer Address not supported in CLIENTID option. No DhcpRelay Record created.");
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_FAIL);
return;
}
} else {
log.warn("CLIENTID option NOT found. Don't create DhcpRelay Record.");
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENTID_FAIL);
return;
}
HostId leafHostId = HostId.hostId(leafClientMac, vlanId);
DhcpRecord record = dhcpRelayStore.getDhcpRecord(leafHostId).orElse(null);
if (record == null) {
record = new DhcpRecord(leafHostId);
} else {
record = record.clone();
}
Boolean isMsgRelease = Dhcp6HandlerUtil.isDhcp6Release(dhcp6Packet);
IpAddressInfo ipInfo;
PdPrefixInfo pdInfo = null;
if (directConnFlag) {
// Add to host store if it is connected to network directly
ipInfo = extractIpAddress(dhcp6Packet);
if (ipInfo != null) {
if (isMsgRelease) {
HostId hostId = HostId.hostId(srcMac, vlanId);
log.debug("remove Host {} ip for directly connected.", hostId.toString());
providerService.removeIpFromHost(hostId, ipInfo.ip6Address);
}
} else {
log.debug("ipAddress not found. Do not remove Host {} for directly connected.", HostId.hostId(srcMac, vlanId).toString());
}
leafMsgType = dhcp6Packet.getMsgType();
} else {
// Remove from route store if it is not connected to network directly
// pick out the first link-local ip address
IpAddress nextHopIp = getFirstIpByHost(directConnFlag, srcMac, vlanId);
if (nextHopIp == null) {
log.warn("Can't find link-local IP address of gateway mac {} vlanId {}", srcMac, vlanId);
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_GW);
return;
}
DHCP6 leafDhcp = Dhcp6HandlerUtil.getDhcp6Leaf(dhcp6Packet);
ipInfo = extractIpAddress(leafDhcp);
if (ipInfo == null) {
log.debug("ip is null");
} else {
if (isMsgRelease) {
Route routeForIP = new Route(Route.Source.DHCP, ipInfo.ip6Address.toIpPrefix(), nextHopIp);
log.debug("removing route of 128 address for indirectly connected.");
log.debug("128 ip {}, nexthop {}", HexString.toHexString(ipInfo.ip6Address.toOctets(), ":"), HexString.toHexString(nextHopIp.toOctets(), ":"));
routeStore.removeRoute(routeForIP);
}
}
pdInfo = extractPrefix(leafDhcp);
if (pdInfo == null) {
log.debug("ipPrefix is null ");
} else {
if (isMsgRelease) {
Route routeForPrefix = new Route(Route.Source.DHCP, pdInfo.pdPrefix, nextHopIp);
log.debug("removing route of PD for indirectly connected.");
log.debug("pd ip {}, nexthop {}", HexString.toHexString(pdInfo.pdPrefix.address().toOctets(), ":"), HexString.toHexString(nextHopIp.toOctets(), ":"));
routeStore.removeRoute(routeForPrefix);
if (this.dhcpFpmEnabled) {
dhcpFpmPrefixStore.removeFpmRecord(pdInfo.pdPrefix);
}
}
}
leafMsgType = leafDhcp.getMsgType();
}
if (isMsgRelease) {
log.debug("DHCP6 RELEASE msg.");
if (record != null) {
if (ipInfo != null) {
log.debug("DhcpRelay Record ip6Address is set to null.");
record.ip6Address(null);
}
if (pdInfo != null) {
log.debug("DhcpRelay Record pdPrefix is set to null.");
}
if (!record.ip6Address().isPresent() && !record.pdPrefix().isPresent()) {
log.warn("IP6 address and IP6 PD both are null. Remove record.");
// do not remove a record. Let timer task handler it.
// dhcpRelayStore.removeDhcpRecord(HostId.hostId(leafClientMac, vlanId));
}
}
}
if (record != null) {
record.getV6Counters().incrementCounter(Dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
record.addLocation(new HostLocation(location, System.currentTimeMillis()));
record.ip6Status(DHCP6.MsgType.getType(leafMsgType));
record.setDirectlyConnected(directConnFlag);
if (!directConnFlag) {
// Update gateway mac address if the host is not directly connected
record.nextHop(srcMac);
}
record.updateLastSeen();
}
dhcpRelayStore.updateDhcpRecord(leafHostId, record);
/*
// TODO Use AtomicInteger for the counters
try {
recordSemaphore.acquire();
try {
dhcpRelayCountersStore.incrementCounter(gCount, Dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
} finally {
// calling release() after a successful acquire()
recordSemaphore.release();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
*/
}
use of org.onosproject.dhcprelay.store.DhcpRecord in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method findNextHopIp6FromRelayStore.
public Ip6Address findNextHopIp6FromRelayStore(Ip6Address clientAddress) {
DhcpRecord dr = getDhcpRelayRecordFor(clientAddress);
if (dr != null) {
Optional<MacAddress> nextHopMac = dr.nextHop();
if (nextHopMac.isPresent()) {
// find the local ip6 from the host store
HostId gwHostId = HostId.hostId(nextHopMac.get(), dr.vlanId());
Host gwHost = hostService.getHost(gwHostId);
if (gwHost == null) {
log.warn("Can't find next hop host ID {}", gwHostId);
return null;
}
Ip6Address nextHopIp = gwHost.ipAddresses().stream().filter(IpAddress::isIp6).filter(IpAddress::isLinkLocal).map(IpAddress::getIp6Address).findFirst().orElse(null);
log.info("findNextHopIp6FromRelayStore " + clientAddress + " got mac " + nextHopMac.toString() + " ip6 " + nextHopIp);
return nextHopIp;
}
} else {
log.warn("findNextHopIp6FromRelayStore could NOT find next hop for " + clientAddress);
return null;
}
return null;
}
use of org.onosproject.dhcprelay.store.DhcpRecord 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()));
}
});
}
Aggregations