use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method hostUpdated.
private void hostUpdated(Host host, List<DhcpServerInfo> serverInfoList) {
serverInfoList.stream().forEach(serverInfo -> {
Ip6Address serverIp = serverInfo.getDhcpServerIp6().orElse(null);
Ip6Address targetIp = serverInfo.getDhcpGatewayIp6().orElse(null);
if (targetIp == null) {
targetIp = serverIp;
}
if (targetIp != null) {
if (host.ipAddresses().contains(targetIp)) {
serverInfo.setDhcpConnectMac(host.mac());
serverInfo.setDhcpConnectVlan(host.vlan());
requestDhcpPacket(serverIp);
}
}
});
}
use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method handleLeaseQuery6ReplyMsg.
public void handleLeaseQuery6ReplyMsg(PacketContext context, DHCP6 dhcp6Payload) {
ConnectPoint inPort = context.inPacket().receivedFrom();
log.info("Got LQV6-REPLY on port {}", inPort);
List<Dhcp6Option> lopt = dhcp6Payload.getOptions();
log.info("Options list: {}", lopt);
// find out if this lease is known is
Dhcp6ClientDataOption clientDataOption = dhcp6Payload.getOptions().stream().filter(opt -> opt instanceof Dhcp6ClientDataOption).map(pld -> (Dhcp6ClientDataOption) pld).findFirst().orElse(null);
if (clientDataOption == null) {
log.warn("clientDataOption option is not present, " + "lease is UNKNOWN - not adding any new route...");
} else {
Dhcp6IaAddressOption aiAddressOption = clientDataOption.getOptions().stream().filter(opt -> opt instanceof Dhcp6IaAddressOption).map(pld -> (Dhcp6IaAddressOption) pld).findFirst().orElse(null);
Dhcp6ClientIdOption clientIdOption = clientDataOption.getOptions().stream().filter(opt -> opt instanceof Dhcp6ClientIdOption).map(pld -> (Dhcp6ClientIdOption) pld).findFirst().orElse(null);
if (aiAddressOption == null) {
log.warn("clientDataOption from DHCP server does not " + "contains Dhcp6IaAddressOption for the client - giving up...");
} else {
Ip6Address clientAddress = aiAddressOption.getIp6Address();
MacAddress clientMacAddress = MacAddress.valueOf(clientIdOption.getDuid().getLinkLayerAddress());
Ethernet packet = context.inPacket().parsed();
VlanId vlanId = VlanId.vlanId(packet.getVlanID());
MacAddress potentialNextHopMac = findNextHopMacForIp6FromRelayStore(clientAddress, clientMacAddress, vlanId);
if (potentialNextHopMac == null) {
log.warn("Can't find next hop host mac for client {} mac:{}/{}", clientAddress, clientMacAddress, vlanId);
return;
} else {
log.info("Next hop mac for {}/{}/{} is {}", clientAddress, clientMacAddress, vlanId, potentialNextHopMac.toString());
}
// search the next hop in the hosts store
HostId gwHostId = HostId.hostId(potentialNextHopMac, vlanId);
Host gwHost = hostService.getHost(gwHostId);
if (gwHost == null) {
log.warn("Can't find next hop host ID {}", gwHostId);
return;
}
Ip6Address nextHopIp = gwHost.ipAddresses().stream().filter(IpAddress::isIp6).filter(IpAddress::isLinkLocal).map(IpAddress::getIp6Address).findFirst().orElse(null);
if (nextHopIp == null) {
log.warn("Can't find IP6 address of next hop {}", gwHost);
return;
}
log.info("client " + clientAddress + " is known !");
Route routeForIP6 = new Route(Route.Source.DHCP, clientAddress.toIpPrefix(), nextHopIp);
log.debug("updating route of Client for indirectly connected.");
log.debug("client ip: " + clientAddress + ", next hop ip6: " + nextHopIp);
routeStore.updateRoute(routeForIP6);
}
}
}
use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method getHostInfoForServerInfo.
/**
* Checks if serverInfo's host info (mac and vlan) is filled in; if not, fills in.
*
* @param serverInfo server information
* @return newServerInfo if host info can be either found or filled in.
*/
private DhcpServerInfo getHostInfoForServerInfo(DhcpServerInfo serverInfo, List<DhcpServerInfo> sererInfoList) {
DhcpServerInfo newServerInfo = null;
MacAddress dhcpServerConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
VlanId dhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
ConnectPoint dhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
if (dhcpServerConnectMac != null && dhcpConnectVlan != null) {
newServerInfo = serverInfo;
log.debug("DHCP server {} host info found. ConnectPt{} Mac {} vlan {}", serverInfo.getDhcpServerIp6(), dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
} else {
log.debug("DHCP server {} not resolve yet connectPt {} mac {} vlan {}", serverInfo.getDhcpServerIp6(), dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
Ip6Address ipToProbe;
if (serverInfo.getDhcpGatewayIp6().isPresent()) {
ipToProbe = serverInfo.getDhcpGatewayIp6().get();
} else {
ipToProbe = serverInfo.getDhcpServerIp6().orElse(null);
}
String hostToProbe = serverInfo.getDhcpGatewayIp6().map(ip -> "gateway").orElse("server");
log.debug("Dynamically probing to resolve {} IP {}", hostToProbe, ipToProbe);
hostService.startMonitoringIp(ipToProbe);
Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
if (!hosts.isEmpty()) {
int serverInfoIndex = sererInfoList.indexOf(serverInfo);
Host host = hosts.iterator().next();
serverInfo.setDhcpConnectVlan(host.vlan());
serverInfo.setDhcpConnectMac(host.mac());
// replace the serverInfo in the list
sererInfoList.set(serverInfoIndex, serverInfo);
newServerInfo = serverInfo;
log.warn("Dynamically host found host {}", host);
} else {
log.debug("No host found host ip {} dynamically", ipToProbe);
}
}
return newServerInfo;
}
use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class IPv6AddressTlv method read.
/**
* Reads the channel buffer and returns object of IPv6AddressTlv.
*
* @param cb channelBuffer
* @param type address type
* @return object of IPv6AddressTlv
* @throws BgpParseException while parsing IPv6AddressTlv
*/
public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
if (ipAddress.isMulticastAddress()) {
throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
}
Ip6Address address = Ip6Address.valueOf(ipAddress);
return IPv6AddressTlv.of(address, type);
}
use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class FpmManager method sendRouteUpdateToChannel.
private void sendRouteUpdateToChannel(boolean isAdd, IpPrefix prefix, Channel ch) {
if (!pdPushEnabled) {
return;
}
int raLength;
short addrFamily;
// Build route attributes.
if (prefix.isIp4()) {
List<Ip4Address> pdPushNextHopList;
if (pdPushNextHopIPv4 == null || pdPushNextHopIPv4.size() == 0) {
log.info("Prefix not pushed because ipv4 next-hop is null.");
return;
}
pdPushNextHopList = pdPushNextHopIPv4;
raLength = Ip4Address.BYTE_LENGTH + RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH;
addrFamily = RtNetlink.RT_ADDRESS_FAMILY_INET;
for (Ip4Address pdPushNextHop : pdPushNextHopList) {
log.trace("IPv4 next hop is:" + pdPushNextHop);
updateRoute(pdPushNextHop, isAdd, prefix, ch, raLength, addrFamily);
}
} else {
List<Ip6Address> pdPushNextHopList;
if (pdPushNextHopIPv6 == null || pdPushNextHopIPv6.size() == 0) {
log.info("Prefix not pushed because ipv6 next-hop is null.");
return;
}
pdPushNextHopList = pdPushNextHopIPv6;
raLength = Ip6Address.BYTE_LENGTH + RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH;
addrFamily = RtNetlink.RT_ADDRESS_FAMILY_INET6;
for (Ip6Address pdPushNextHop : pdPushNextHopList) {
log.trace("IPv6 next hop is:" + pdPushNextHop);
updateRoute(pdPushNextHop, isAdd, prefix, ch, raLength, addrFamily);
}
}
}
Aggregations