Search in sources :

Example 1 with BgpSpeakers

use of org.onosproject.artemis.BgpSpeakers 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)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 CharsetUtil (io.netty.util.CharsetUtil)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 JSONObject (org.json.JSONObject)1 TYPE_IPV4 (org.onlab.packet.Ethernet.TYPE_IPV4)1 IpAddress (org.onlab.packet.IpAddress)1 IpPrefix (org.onlab.packet.IpPrefix)1 TpPort (org.onlab.packet.TpPort)1 ArtemisDeaggregator (org.onosproject.artemis.ArtemisDeaggregator)1 ArtemisEventListener (org.onosproject.artemis.ArtemisEventListener)1 ArtemisMoasAgent (org.onosproject.artemis.ArtemisMoasAgent)1 ArtemisPacketProcessor (org.onosproject.artemis.ArtemisPacketProcessor)1