Bug 3240 3613: Asymetric policy in neutron
[groupbasedpolicy.git] / neutron-mapper / src / main / java / org / opendaylight / groupbasedpolicy / neutron / mapper / infrastructure / NetworkClient.java
diff --git a/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkClient.java b/neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/infrastructure/NetworkClient.java
new file mode 100644 (file)
index 0000000..8ce6717
--- /dev/null
@@ -0,0 +1,67 @@
+package org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure;
+
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroup.IntraGroupPolicy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.endpoint.group.ConsumerNamedSelector;
+
+import com.google.common.base.Preconditions;
+
+public class NetworkClient {
+
+    private static final Name NETWORK_CLIENT_EPG_NAME = new Name("NETWORK_CLIENT");
+    private static final Description NETWORK_CLIENT_EPG_DESC = new Description("Represents DHCP and DNS clients.");
+    /**
+     * ID of {@link #EPG}
+     */
+    public static final EndpointGroupId EPG_ID = new EndpointGroupId("ccc5e444-573c-11e5-885d-feff819cdc9f");
+    /**
+     * Network-client endpoint-group consuming no contract
+     */
+    public static final EndpointGroup EPG;
+
+    static {
+        EPG = createNetworkClientEpg();
+    }
+
+    private static EndpointGroup createNetworkClientEpg() {
+        return new EndpointGroupBuilder().setId(EPG_ID)
+            .setName(NETWORK_CLIENT_EPG_NAME)
+            .setIntraGroupPolicy(IntraGroupPolicy.RequireContract)
+            .setDescription(NETWORK_CLIENT_EPG_DESC)
+            .build();
+    }
+
+    /**
+     * Puts {@link #EPG} to {@link LogicalDatastoreType#CONFIGURATION}
+     * 
+     * @param tenantId location of {@link #EPG}
+     * @param wTx transaction where {@link #EPG} is written
+     */
+    public static void writeNetworkClientEntitiesToTenant(TenantId tenantId, WriteTransaction wTx) {
+        wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, EPG_ID), EPG, true);
+    }
+
+    /**
+     * Puts consumer-named-selector to {@link #EPG} in {@link LogicalDatastoreType#CONFIGURATION}
+     * 
+     * @param tenantId tenantId location of {@link #EPG}
+     * @param consumerNamedSelector is added to {@link #EPG}
+     * @param wTx transaction where the given consumer-named-selector is written
+     */
+    public static void writeConsumerNamedSelector(TenantId tenantId, ConsumerNamedSelector consumerNamedSelector,
+            WriteTransaction wTx) {
+        Preconditions.checkNotNull(consumerNamedSelector);
+        wTx.put(LogicalDatastoreType.CONFIGURATION,
+                IidFactory.consumerNamedSelectorIid(tenantId, EPG_ID, consumerNamedSelector.getName()),
+                consumerNamedSelector, true);
+    }
+
+}