Search in sources :

Example 61 with IpPrefix

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);
                    });
                }
            }));
        }
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) CoreService(org.onosproject.core.CoreService) ArtemisService(org.onosproject.artemis.ArtemisService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) ArtemisEventListener(org.onosproject.artemis.ArtemisEventListener) BgpInfoService(org.onosproject.routing.bgp.BgpInfoService) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Unpooled(io.netty.buffer.Unpooled) ArtemisMoasAgent(org.onosproject.artemis.ArtemisMoasAgent) JSONObject(org.json.JSONObject) FlowRuleService(org.onosproject.net.flow.FlowRuleService) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Port(org.onosproject.net.Port) Map(java.util.Map) CharsetUtil(io.netty.util.CharsetUtil) ApplicationId(org.onosproject.core.ApplicationId) ArtemisPacketProcessor(org.onosproject.artemis.ArtemisPacketProcessor) TYPE_IPV4(org.onlab.packet.Ethernet.TYPE_IPV4) MoasClientController(org.onosproject.artemis.impl.moas.MoasClientController) Deactivate(org.osgi.service.component.annotations.Deactivate) BgpSpeakers(org.onosproject.artemis.BgpSpeakers) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Sets(com.google.common.collect.Sets) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) QuaggaBgpSpeakers(org.onosproject.artemis.impl.bgpspeakers.QuaggaBgpSpeakers) MoasServerController(org.onosproject.artemis.impl.moas.MoasServerController) InterfaceService(org.onosproject.net.intf.InterfaceService) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ByteBuf(io.netty.buffer.ByteBuf) ArtemisDeaggregator(org.onosproject.artemis.ArtemisDeaggregator) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) TpPort(org.onlab.packet.TpPort) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ArtemisMessage(org.onosproject.artemis.impl.objects.ArtemisMessage) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Maps(com.google.common.collect.Maps) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) Reference(org.osgi.service.component.annotations.Reference) MoasClientController(org.onosproject.artemis.impl.moas.MoasClientController)

Example 62 with IpPrefix

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;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Config(org.onosproject.net.config.Config) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Streams(com.google.common.collect.Streams) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ArrayList(java.util.ArrayList) Objects(java.util.Objects) JSONException(org.json.JSONException) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) JsonNode(com.fasterxml.jackson.databind.JsonNode) Collections(java.util.Collections) JSONArray(org.json.JSONArray) IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) Map(java.util.Map)

Example 63 with IpPrefix

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));
            }
        }));
    }
}
Also used : Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) CoreService(org.onosproject.core.CoreService) EventDeliveryService(org.onosproject.event.EventDeliveryService) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) ArtemisService(org.onosproject.artemis.ArtemisService) LoggerFactory(org.slf4j.LoggerFactory) ArtemisEventListener(org.onosproject.artemis.ArtemisEventListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) JSONException(org.json.JSONException) Component(org.osgi.service.component.annotations.Component) JSONObject(org.json.JSONObject) ArtemisDetector(org.onosproject.artemis.ArtemisDetector) Activate(org.osgi.service.component.annotations.Activate) Reference(org.osgi.service.component.annotations.Reference) JSONArray(org.json.JSONArray) IpPrefix(org.onlab.packet.IpPrefix) IpPrefix(org.onlab.packet.IpPrefix) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 64 with IpPrefix

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);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) FpmRecord(org.onosproject.routing.fpm.api.FpmRecord) IpAddress(org.onlab.packet.IpAddress)

Example 65 with IpPrefix

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);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Aggregations

IpPrefix (org.onlab.packet.IpPrefix)107 Test (org.junit.Test)37 IpAddress (org.onlab.packet.IpAddress)29 LinkedList (java.util.LinkedList)24 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)22 BgpHeader (org.onosproject.bgpio.types.BgpHeader)22 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)21 AsPath (org.onosproject.bgpio.types.AsPath)21 BgpValueType (org.onosproject.bgpio.types.BgpValueType)21 Origin (org.onosproject.bgpio.types.Origin)21 OriginType (org.onosproject.bgpio.types.Origin.OriginType)21 Med (org.onosproject.bgpio.types.Med)20 TrafficSelector (org.onosproject.net.flow.TrafficSelector)20 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)19 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)18 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)16 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)14 MacAddress (org.onlab.packet.MacAddress)12