use of org.onosproject.artemis.impl.moas.MoasClientController in project onos by opennetworkinglab.
the class ArtemisDeaggregatorImpl method handleArtemisEvent.
/**
* Handles a artemis event.
*
* @param event the artemis event
*/
protected void handleArtemisEvent(ArtemisEvent event) {
if (event.type().equals(ArtemisEvent.Type.HIJACK_ADDED)) {
IpPrefix receivedPrefix = (IpPrefix) event.subject();
log.info("Deaggregator received a prefix " + receivedPrefix.toString());
// can only de-aggregate /23 subnets and higher
int cidr = receivedPrefix.prefixLength();
if (receivedPrefix.prefixLength() < 24) {
byte[] octets = receivedPrefix.address().toOctets();
int byteGroup = (cidr + 1) / 8, bitPos = 8 - (cidr + 1) % 8;
octets[byteGroup] = (byte) (octets[byteGroup] & ~(1 << bitPos));
String low = IpPrefix.valueOf(IpAddress.Version.INET, octets, cidr + 1).toString();
octets[byteGroup] = (byte) (octets[byteGroup] | (1 << bitPos));
String high = IpPrefix.valueOf(IpAddress.Version.INET, octets, cidr + 1).toString();
String[] prefixes = { low, high };
bgpSpeakers.forEach(bgpSpeakers -> bgpSpeakers.announceSubPrefixes(prefixes));
} else {
log.warn("Initiating MOAS");
artemisService.getConfig().ifPresent(config -> config.monitoredPrefixes().forEach(artemisPrefixes -> {
log.info("checking if {} > {}", artemisPrefixes.prefix(), receivedPrefix);
if (artemisPrefixes.prefix().contains(receivedPrefix)) {
artemisPrefixes.moas().forEach(moasAddress -> {
log.info("Creating a client for {}", moasAddress);
MoasClientController client = new MoasClientController(packetProcessor, moasAddress, config.moasInfo().getTunnelPoints().iterator().next().getLocalIp(), receivedPrefix);
log.info("Running client");
client.run();
moasClientControllers.add(client);
});
}
}));
}
}
}
Aggregations