use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class RouteEntryTest method testInvalidConstructorNullIpv6NextHop.
/**
* Tests invalid class constructor for null IPv6 next-hop.
*/
@Test(expected = NullPointerException.class)
public void testInvalidConstructorNullIpv6NextHop() {
Ip6Prefix prefix = Ip6Prefix.valueOf("1000::/64");
Ip6Address nextHop = null;
new RouteEntry(prefix, nextHop);
}
use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class RouteEntryTest method testNonEquality.
/**
* Tests non-equality of {@link RouteEntry}.
*/
@Test
public void testNonEquality() {
Ip4Prefix prefix1 = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop1 = Ip4Address.valueOf("5.6.7.8");
RouteEntry routeEntry1 = new RouteEntry(prefix1, nextHop1);
// Different
Ip4Prefix prefix2 = Ip4Prefix.valueOf("1.2.3.0/25");
Ip4Address nextHop2 = Ip4Address.valueOf("5.6.7.8");
RouteEntry routeEntry2 = new RouteEntry(prefix2, nextHop2);
Ip4Prefix prefix3 = Ip4Prefix.valueOf("1.2.3.0/24");
// Different
Ip4Address nextHop3 = Ip4Address.valueOf("5.6.7.9");
RouteEntry routeEntry3 = new RouteEntry(prefix3, nextHop3);
assertThat(routeEntry1, Matchers.is(Matchers.not(routeEntry2)));
assertThat(routeEntry1, Matchers.is(Matchers.not(routeEntry3)));
Ip6Prefix prefix4 = Ip6Prefix.valueOf("1000::/64");
Ip6Address nextHop4 = Ip6Address.valueOf("2000::1");
RouteEntry routeEntry4 = new RouteEntry(prefix4, nextHop4);
Ip6Prefix prefix5 = Ip6Prefix.valueOf("1000::/65");
Ip6Address nextHop5 = Ip6Address.valueOf("2000::1");
RouteEntry routeEntry5 = new RouteEntry(prefix5, nextHop5);
Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64");
Ip6Address nextHop6 = Ip6Address.valueOf("2000::2");
RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6);
assertThat(routeEntry4, Matchers.is(Matchers.not(routeEntry5)));
assertThat(routeEntry4, Matchers.is(Matchers.not(routeEntry6)));
}
use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class RouteEntryTest method testEquality.
/**
* Tests equality of {@link RouteEntry}.
*/
@Test
public void testEquality() {
Ip4Prefix prefix1 = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop1 = Ip4Address.valueOf("5.6.7.8");
RouteEntry routeEntry1 = new RouteEntry(prefix1, nextHop1);
Ip4Prefix prefix2 = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop2 = Ip4Address.valueOf("5.6.7.8");
RouteEntry routeEntry2 = new RouteEntry(prefix2, nextHop2);
assertThat(routeEntry1, is(routeEntry2));
Ip6Prefix prefix3 = Ip6Prefix.valueOf("1000::/64");
Ip6Address nextHop3 = Ip6Address.valueOf("2000::2");
RouteEntry routeEntry3 = new RouteEntry(prefix3, nextHop3);
Ip6Prefix prefix4 = Ip6Prefix.valueOf("1000::/64");
Ip6Address nextHop4 = Ip6Address.valueOf("2000::2");
RouteEntry routeEntry4 = new RouteEntry(prefix4, nextHop4);
assertThat(routeEntry3, is(routeEntry4));
}
use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class RouteEntryTest method testGetFields.
/**
* Tests getting the fields of a route entry.
*/
@Test
public void testGetFields() {
Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8");
RouteEntry routeEntry = new RouteEntry(prefix, nextHop);
assertThat(routeEntry.prefix(), is(prefix));
assertThat(routeEntry.nextHop(), is(nextHop));
Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64");
Ip6Address nextHop6 = Ip6Address.valueOf("2000::1");
RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6);
assertThat(routeEntry6.prefix(), is(prefix6));
assertThat(routeEntry6.nextHop(), is(nextHop6));
}
use of org.onlab.packet.Ip6Address in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method setDhcpServerConfigs.
public void setDhcpServerConfigs(Collection<DhcpServerConfig> configs, List<DhcpServerInfo> serverInfoList) {
log.debug("config size {}.", configs.size());
if (configs.size() == 0) {
// no config to update
return;
}
// TODO: currently we pick up first DHCP server config.
// Will use other server configs in the future for HA.
Boolean isConfigValid = false;
for (DhcpServerConfig serverConfig : configs) {
if (serverConfig.getDhcpServerIp6().isPresent()) {
isConfigValid = true;
break;
}
}
if (!isConfigValid) {
log.warn("No IP V6 server address found.");
// No IP V6 address found
return;
}
for (DhcpServerInfo oldServerInfo : serverInfoList) {
// stop monitoring gateway or server
oldServerInfo.getDhcpGatewayIp6().ifPresent(gatewayIp -> {
hostService.stopMonitoringIp(gatewayIp);
});
oldServerInfo.getDhcpServerIp6().ifPresent(serverIp -> {
hostService.stopMonitoringIp(serverIp);
cancelDhcpPacket(serverIp);
});
}
serverInfoList.clear();
for (DhcpServerConfig serverConfig : configs) {
// Create new server info according to the config
DhcpServerInfo newServerInfo = new DhcpServerInfo(serverConfig, DhcpServerInfo.Version.DHCP_V6);
checkState(newServerInfo.getDhcpServerConnectPoint().isPresent(), "Connect point not exists");
checkState(newServerInfo.getDhcpServerIp6().isPresent(), "IP of DHCP server not exists");
log.debug("DHCP server connect point: {}", newServerInfo.getDhcpServerConnectPoint().orElse(null));
log.debug("DHCP server IP: {}", newServerInfo.getDhcpServerIp6().orElse(null));
Ip6Address serverIp = newServerInfo.getDhcpServerIp6().get();
Ip6Address ipToProbe;
if (newServerInfo.getDhcpGatewayIp6().isPresent()) {
ipToProbe = newServerInfo.getDhcpGatewayIp6().get();
} else {
ipToProbe = newServerInfo.getDhcpServerIp6().orElse(null);
}
String hostToProbe = newServerInfo.getDhcpGatewayIp6().map(ip -> "gateway").orElse("server");
log.warn("Probing to resolve {} IP {}", hostToProbe, ipToProbe);
hostService.startMonitoringIp(ipToProbe);
Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
if (!hosts.isEmpty()) {
Host host = hosts.iterator().next();
newServerInfo.setDhcpConnectVlan(host.vlan());
newServerInfo.setDhcpConnectMac(host.mac());
log.warn("Host found host {}", host);
} else {
log.warn("No host found host ip {}", ipToProbe);
}
// Add new server info
synchronized (this) {
serverInfoList.add(newServerInfo);
}
if (!hosts.isEmpty()) {
requestDhcpPacket(serverIp);
}
}
}
Aggregations