use of org.onlab.packet.IpPrefix 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);
});
}
}));
}
}
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class ArtemisConfig method monitoredPrefixes.
/**
* Gets the set of monitored prefixes with the details (prefix, paths and MOAS).
*
* @return artemis class prefixes
*/
Set<ArtemisPrefixes> monitoredPrefixes() {
Set<ArtemisPrefixes> prefixes = Sets.newHashSet();
JsonNode prefixesNode = object.path(PREFIXES);
if (prefixesNode.isMissingNode()) {
log.warn("prefixes field is null!");
return prefixes;
}
prefixesNode.forEach(jsonNode -> {
IpPrefix prefix = IpPrefix.valueOf(jsonNode.get(PREFIX).asText());
JsonNode moasNode = jsonNode.get(MOAS);
Set<IpAddress> moasIps = Streams.stream(moasNode).map(asn -> IpAddress.valueOf(asn.asText())).collect(Collectors.toSet());
JsonNode pathsNode = jsonNode.get(PATHS);
Map<Integer, Map<Integer, Set<Integer>>> paths = Maps.newHashMap();
pathsNode.forEach(path -> addPath(paths, path));
prefixes.add(new ArtemisPrefixes(prefix, moasIps, paths));
});
return prefixes;
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class ArtemisDetectorImpl method handleArtemisEvent.
/**
* Handles a artemis event.
*
* @param event the artemis event
*/
void handleArtemisEvent(ArtemisEvent event) {
// If an instance was deactivated, check whether we need to roll back the upgrade.
if (event.type().equals(ArtemisEvent.Type.BGPUPDATE_ADDED)) {
JSONObject take = (JSONObject) event.subject();
log.info("Received information about monitored prefix " + take.toString());
artemisService.getConfig().ifPresent(config -> config.monitoredPrefixes().forEach(artemisPrefix -> {
try {
IpPrefix prefix = artemisPrefix.prefix(), receivedPrefix;
receivedPrefix = IpPrefix.valueOf(take.getString("prefix"));
if (prefix.contains(receivedPrefix)) {
JSONArray path = take.getJSONArray("path");
int state = artemisPrefix.checkPath(path);
if (state >= 100) {
log.info("BGP Hijack detected; pushing prefix for hijack Deaggregation");
eventDispatcher.post(new ArtemisEvent(ArtemisEvent.Type.HIJACK_ADDED, receivedPrefix));
} else {
log.info("BGP Update is legit");
}
}
} catch (JSONException e) {
log.error(ExceptionUtils.getFullStackTrace(e));
}
}));
}
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class DhcpFpmAddCommand method doExecute.
@Override
protected void doExecute() {
IpPrefix prefix = IpPrefix.valueOf(prefixString);
IpAddress nextHop = IpAddress.valueOf(nextHopString);
FpmRecord record = new FpmRecord(prefix, nextHop, FpmRecord.Type.DHCP_RELAY);
DHCP_RELAY_SERVICE.addFpmRecord(prefix, record);
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class IntentSynchronizerTest method testWithdraw.
/**
* Tests the behavior of the withdraw API, both when the synchronizer has
* leadership and when it does not.
*/
@Test
public void testWithdraw() {
IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
Intent intent = intentBuilder(prefix, "00:00:00:00:00:01", SW1_ETH1);
// Submit an intent first so we can withdraw it later
intentService.submit(intent);
intentService.withdraw(intent);
EasyMock.expect(intentService.getIntents()).andReturn(Collections.emptyList()).anyTimes();
EasyMock.replay(intentService);
// Give the intent synchronizer leadership so it will submit intents
// to the intent service
intentSynchronizer.modifyPrimary(true);
// Test the submit then withdraw
intentSynchronizer.submit(intent);
intentSynchronizer.withdraw(intent);
EasyMock.verify(intentService);
// Now we'll remove leadership from the intent synchronizer and verify
// that it does not withdraw any intents to the intent service when we
// call the withdraw API
EasyMock.reset(intentService);
EasyMock.replay(intentService);
intentSynchronizer.modifyPrimary(false);
intentSynchronizer.submit(intent);
intentSynchronizer.withdraw(intent);
EasyMock.verify(intentService);
}
Aggregations