PortHandler portHandler = new PortHandler(dataBroker, routingNode);\r
dataChangeProviders.add(new PortAware(portHandler, dataBroker));\r
dataChangeProviders.add(new NetworkAware(dataBroker));\r
+ dataChangeProviders.add(new SubnetAware(dataBroker));\r
}\r
\r
@Override\r
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.processors;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Created by Shakib Ahmed on 4/3/17.
+ */
+public class SubnetAware implements MappingProvider<Subnet>{
+ private static final Logger LOG = LoggerFactory.getLogger(SubnetAware.class);
+
+ private SubnetHandler subnetHandler;
+
+ public SubnetAware(DataBroker dataBroker) {
+ subnetHandler = new SubnetHandler(dataBroker);
+ }
+
+ @Override
+ public InstanceIdentifier<Subnet> getNeutronDtoIid() {
+ return InstanceIdentifier.builder(Neutron.class).child(Subnets.class).child(Subnet.class).build();
+ }
+
+ @Override
+ public void processCreatedNeutronDto(Subnet subnet) {
+ LOG.debug("Got create for subnet: {}", subnet.getUuid().getValue());
+ subnetHandler.processCreatedNeutronDto(subnet);
+ }
+
+ @Override
+ public void processUpdatedNeutronDto(Subnet original, Subnet delta) {
+ LOG.debug("Got update of subnet: {}", original.getUuid().getValue());
+ subnetHandler.processUpdatedNeutronDto(original, delta);
+ }
+
+ @Override
+ public void processDeletedNeutronDto(Subnet subnet) {
+ LOG.debug("Got delete of subnet: {}", subnet.getUuid().getValue());
+ subnetHandler.processDeletedNeutronDto(subnet);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.processors;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.util.HandlerUtil;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Created by Shakib Ahmed on 4/3/17.
+ */
+public class SubnetHandler {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SubnetHandler.class);
+
+ private final DataBroker dataBroker;
+
+ public SubnetHandler(DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
+ }
+
+ public void processCreatedNeutronDto(Subnet subnet) {
+ GbpSubnet gbpSubnet = HandlerUtil.toGbpSubnet(subnet);
+
+ if (gbpSubnet != null) {
+ ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+ rwTx.put(LogicalDatastoreType.CONFIGURATION,
+ HandlerUtil.getInstanceIdentifier(gbpSubnet.getId()),
+ gbpSubnet, true);
+ DataStoreHelper.submitToDs(rwTx);
+ }
+ }
+
+ public void processUpdatedNeutronDto(Subnet oldSubnet, Subnet delta) {
+ Preconditions.checkState(oldSubnet.getUuid().equals(delta.getUuid()),
+ "Uuid change not allowed!");
+ GbpSubnet gbpSubnet = HandlerUtil.toGbpSubnet(delta);
+
+ if (gbpSubnet != null) {
+ ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+ rwTx.put(LogicalDatastoreType.CONFIGURATION,
+ HandlerUtil.getInstanceIdentifier(gbpSubnet.getId()),
+ gbpSubnet, true);
+ DataStoreHelper.submitToDs(rwTx);
+ }
+ }
+
+ public void processDeletedNeutronDto(Subnet subnet) {
+ GbpSubnet gbpSubnet = HandlerUtil.toGbpSubnet(subnet);
+ if (gbpSubnet != null) {
+ ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+ rwTx.put(LogicalDatastoreType.CONFIGURATION,
+ HandlerUtil.getInstanceIdentifier(gbpSubnet.getId()),
+ gbpSubnet, true);
+ DataStoreHelper.removeIfExists(LogicalDatastoreType.CONFIGURATION,
+ HandlerUtil.getInstanceIdentifier(gbpSubnet.getId()),
+ rwTx);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.util;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnetKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.gbp.subnet.base.attributes.AllocationPools;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.gbp.subnet.base.attributes.AllocationPoolsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.gbp.subnet.base.attributes.AllocationPoolsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import java.util.stream.Collectors;
+
+/**
+ * Created by Shakib Ahmed on 4/25/17.
+ */
+public class HandlerUtil {
+ public static GbpSubnet toGbpSubnet(Subnet subnet) {
+ GbpSubnetBuilder gbpSubnetBuilder = new GbpSubnetBuilder();
+ gbpSubnetBuilder.setKey(new GbpSubnetKey(subnet.getUuid().getValue()));
+ gbpSubnetBuilder.setId(subnet.getUuid().getValue());
+ gbpSubnetBuilder.setCidr(subnet.getCidr());
+ gbpSubnetBuilder.setGatewayIp(subnet.getGatewayIp());
+ gbpSubnetBuilder.setAllocationPools(subnet.getAllocationPools()
+ .stream()
+ .map(allocationPools -> toGbpAllocationPools(allocationPools))
+ .collect(Collectors.toList()));
+ return gbpSubnetBuilder.build();
+ }
+
+ private static AllocationPools toGbpAllocationPools(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.
+ subnet.attributes.AllocationPools pool) {
+ AllocationPoolsBuilder allocationPoolsBuilder = new AllocationPoolsBuilder();
+ allocationPoolsBuilder.setKey(new AllocationPoolsKey(pool.getStart()));
+ allocationPoolsBuilder.setStart(pool.getStart());
+ allocationPoolsBuilder.setEnd(pool.getEnd());
+ return allocationPoolsBuilder.build();
+ }
+
+ public static InstanceIdentifier<GbpSubnet> getInstanceIdentifier(String subnetUuid) {
+ return InstanceIdentifier
+ .builder(Config.class)
+ .child(GbpSubnet.class, new GbpSubnetKey(subnetUuid)).build();
+ }
+}
\ No newline at end of file
import org.opendaylight.groupbasedpolicy.renderer.vpp.api.BridgeDomainManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.AclManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.GbpSubnetListener;
import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.RendererPolicyListener;
import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.VppEndpointListener;
import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.VppNodeListener;
private VppNodeListener vppNodeListener;
private VppEndpointListener vppEndpointListener;
private RendererPolicyListener rendererPolicyListener;
+ private GbpSubnetListener vppGbpSubnetListener;
VppRenderer(@Nonnull DataBroker dataBroker, @Nonnull BindingAwareBroker bindingAwareBroker,
@Nullable String publicInterfaces) {
vppNodeListener = new VppNodeListener(dataBroker, vppNodeManager, dtoEventBus);
vppEndpointListener = new VppEndpointListener(dataBroker, dtoEventBus);
rendererPolicyListener = new RendererPolicyListener(dataBroker, dtoEventBus);
+ vppGbpSubnetListener = new GbpSubnetListener(dataBroker, dtoEventBus);
registerToRendererManager();
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.vpp.event;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnet;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+/**
+ * Created by Shakib Ahmed on 4/26/17.
+ */
+public class GbpSubnetEvent extends DtoChangeEvent<GbpSubnet>{
+
+ public GbpSubnetEvent(@Nonnull InstanceIdentifier<GbpSubnet> iid, @Nullable GbpSubnet before, @Nullable GbpSubnet after) {
+ super(iid, before, after);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.vpp.listener;
+
+import com.google.common.base.Preconditions;
+import com.google.common.eventbus.EventBus;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.event.GbpSubnetEvent;
+import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnet;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Created by Shakib Ahmed on 4/25/17.
+ */
+public class GbpSubnetListener extends DataTreeChangeHandler<GbpSubnet> {
+ private static final Logger LOG = LoggerFactory.getLogger(GbpSubnetListener.class);
+ private EventBus eventBus;
+
+ public GbpSubnetListener(DataBroker dataBroker, EventBus eventbus) {
+ super(dataBroker);
+ this.eventBus = Preconditions.checkNotNull(eventbus);
+ registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+ InstanceIdentifier.builder(Config.class).child(GbpSubnet.class).build()));
+ }
+
+ @Override
+ protected void onWrite(DataObjectModification<GbpSubnet> rootNode, InstanceIdentifier<GbpSubnet> rootIdentifier) {
+ GbpSubnetEvent writeEvent = new GbpSubnetEvent(rootIdentifier,
+ rootNode.getDataBefore(),
+ rootNode.getDataAfter());
+ eventBus.post(writeEvent);
+ }
+
+ @Override
+ protected void onDelete(DataObjectModification<GbpSubnet> rootNode, InstanceIdentifier<GbpSubnet> rootIdentifier) {
+ GbpSubnetEvent deleteEvent = new GbpSubnetEvent(rootIdentifier,
+ rootNode.getDataBefore(),
+ rootNode.getDataAfter());
+ eventBus.post(deleteEvent);
+ }
+
+ @Override
+ protected void onSubtreeModified(DataObjectModification<GbpSubnet> rootNode, InstanceIdentifier<GbpSubnet> rootIdentifier) {
+ GbpSubnetEvent modificationEvent = new GbpSubnetEvent(rootIdentifier,
+ rootNode.getDataBefore(),
+ rootNode.getDataAfter());
+ eventBus.post(modificationEvent);
+ }
+}
}
}
+ grouping gbp-subnet-base-attributes {
+ leaf id {
+ description "Subnet UUID of neutron subnet call.";
+ type string;
+ }
+ leaf cidr {
+ type inet:ip-prefix;
+ description "cidr representing IP range for this subnet, based on IP version";
+ }
+ leaf gateway-ip {
+ type inet:ip-address;
+ description "default gateway used by devices in this subnet";
+ }
+ list allocation-pools {
+ description "Sub-ranges of cidr available for dynamic allocation to ports";
+ key start;
+ leaf start {
+ type inet:ip-address;
+ }
+ leaf end {
+ type inet:ip-address;
+ }
+ }
+ }
+
container config {
list vpp-endpoint {
description "Renderer creates/removes interface on VPP node based on given parameters.";
type l2-types:vlan-id;
}
}
+
+ list gbp-subnet {
+ key "id";
+ uses gbp-subnet-base-attributes;
+ }
}
augment "rend:renderers/rend:renderer/rend:renderer-nodes/rend:renderer-node" {