0ac5cf05e860c9ba5bf5ec8fb4616db7660ef80c
[groupbasedpolicy.git] / neutron-mapper / src / main / java / org / opendaylight / groupbasedpolicy / neutron / mapper / infrastructure / NetworkClient.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure;
10
11 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.groupbasedpolicy.util.IidFactory;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup.IntraGroupPolicy;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ConsumerNamedSelector;
22
23 import com.google.common.base.Preconditions;
24
25 public class NetworkClient {
26
27     private static final Name NETWORK_CLIENT_EPG_NAME = new Name("NETWORK_CLIENT");
28     private static final Description NETWORK_CLIENT_EPG_DESC = new Description("Represents DHCP and DNS clients.");
29     /**
30      * ID of {@link #EPG}
31      */
32     public static final EndpointGroupId EPG_ID = new EndpointGroupId("ccc5e444-573c-11e5-885d-feff819cdc9f");
33     /**
34      * Network-client endpoint-group consuming no contract
35      */
36     public static final EndpointGroup EPG;
37
38     static {
39         EPG = createNetworkClientEpg();
40     }
41
42     private static EndpointGroup createNetworkClientEpg() {
43         return new EndpointGroupBuilder().setId(EPG_ID)
44             .setName(NETWORK_CLIENT_EPG_NAME)
45             .setIntraGroupPolicy(IntraGroupPolicy.RequireContract)
46             .setDescription(NETWORK_CLIENT_EPG_DESC)
47             .build();
48     }
49
50     /**
51      * Puts {@link #EPG} to {@link LogicalDatastoreType#CONFIGURATION}
52      *
53      * @param tenantId location of {@link #EPG}
54      * @param wTx transaction where {@link #EPG} is written
55      */
56     public static void writeNetworkClientEntitiesToTenant(TenantId tenantId, WriteTransaction wTx) {
57         wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, EPG_ID), EPG, true);
58     }
59
60     /**
61      * Puts consumer-named-selector to {@link #EPG} in {@link LogicalDatastoreType#CONFIGURATION}
62      *
63      * @param tenantId tenantId location of {@link #EPG}
64      * @param consumerNamedSelector is added to {@link #EPG}
65      * @param wTx transaction where the given consumer-named-selector is written
66      */
67     public static void writeConsumerNamedSelector(TenantId tenantId, ConsumerNamedSelector consumerNamedSelector,
68             WriteTransaction wTx) {
69         Preconditions.checkNotNull(consumerNamedSelector);
70         wTx.put(LogicalDatastoreType.CONFIGURATION,
71                 IidFactory.consumerNamedSelectorIid(tenantId, EPG_ID, consumerNamedSelector.getName()),
72                 consumerNamedSelector, true);
73     }
74
75 }