Bug 4724 added containers to tenant
[groupbasedpolicy.git] / groupbasedpolicy / src / main / java / org / opendaylight / groupbasedpolicy / util / IidFactory.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.util;
10
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionDefinitionId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClauseName;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RuleName;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SelectorName;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubjectName;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.Endpoints;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Key;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3PrefixKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.Tenants;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRef;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRefKey;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionKey;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionKey;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantKey;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContext;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.Policy;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomain;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomainKey;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainKey;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3Context;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextKey;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetKey;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.Contract;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.ContractKey;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupKey;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstances;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Clause;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.ClauseKey;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Subject;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.SubjectKey;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.Rule;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.RuleKey;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ConsumerNamedSelector;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ConsumerNamedSelectorKey;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ProviderNamedSelector;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ProviderNamedSelectorKey;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstanceKey;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceKey;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.RendererName;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.RendererKey;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.Interests;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.FollowedTenants;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.FollowedTenant;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.FollowedTenantKey;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.followed.tenant.FollowedEndpointGroup;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.followed.tenant.FollowedEndpointGroupKey;
85 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
86
87 public class IidFactory {
88
89     private IidFactory() {
90         throw new UnsupportedOperationException();
91     }
92
93     private static final InstanceIdentifier<Endpoints> ENDPOINTS_IID = InstanceIdentifier.builder(Endpoints.class).build();
94
95     public static InstanceIdentifier<Tenant> tenantIid(TenantId id) {
96         return InstanceIdentifier.builder(Tenants.class).child(Tenant.class, new TenantKey(id)).build();
97     }
98
99     public static InstanceIdentifier<EndpointGroup> endpointGroupIid(TenantId tenantId, EndpointGroupId epgId) {
100         return InstanceIdentifier.builder(Tenants.class)
101             .child(Tenant.class, new TenantKey(tenantId))
102             .child(Policy.class)
103             .child(EndpointGroup.class, new EndpointGroupKey(epgId))
104             .build();
105     }
106
107     public static InstanceIdentifier<Contract> contractIid(TenantId tenantId, ContractId contractId) {
108         return InstanceIdentifier.builder(Tenants.class)
109             .child(Tenant.class, new TenantKey(tenantId))
110             .child(Policy.class)
111             .child(Contract.class, new ContractKey(contractId))
112             .build();
113     }
114
115     public static InstanceIdentifier<Subject> subjectIid(TenantId tenantId, ContractId contractId,
116             SubjectName subjectName) {
117         return InstanceIdentifier.builder(Tenants.class)
118             .child(Tenant.class, new TenantKey(tenantId))
119             .child(Policy.class)
120             .child(Contract.class, new ContractKey(contractId))
121             .child(Subject.class, new SubjectKey(subjectName))
122             .build();
123     }
124
125     public static InstanceIdentifier<ProviderNamedSelector> providerNamedSelectorIid(TenantId tenantId,
126             EndpointGroupId epgId, SelectorName providerSelectorName) {
127         return InstanceIdentifier.builder(Tenants.class)
128             .child(Tenant.class, new TenantKey(tenantId))
129             .child(Policy.class)
130             .child(EndpointGroup.class, new EndpointGroupKey(epgId))
131             .child(ProviderNamedSelector.class, new ProviderNamedSelectorKey(providerSelectorName))
132             .build();
133     }
134
135     public static InstanceIdentifier<ConsumerNamedSelector> consumerNamedSelectorIid(TenantId tenantId,
136             EndpointGroupId epgId, SelectorName consumerSelectorName) {
137         return InstanceIdentifier.builder(Tenants.class)
138             .child(Tenant.class, new TenantKey(tenantId))
139             .child(Policy.class)
140             .child(EndpointGroup.class, new EndpointGroupKey(epgId))
141             .child(ConsumerNamedSelector.class, new ConsumerNamedSelectorKey(consumerSelectorName))
142             .build();
143     }
144
145     public static InstanceIdentifier<Clause> clauseIid(TenantId tenantId, ContractId contractId, ClauseName clauseName) {
146         return InstanceIdentifier.builder(Tenants.class)
147             .child(Tenant.class, new TenantKey(tenantId))
148             .child(Policy.class)
149             .child(Contract.class, new ContractKey(contractId))
150             .child(Clause.class, new ClauseKey(clauseName))
151             .build();
152     }
153
154     public static InstanceIdentifier<Rule> ruleIid(TenantId tenantId, ContractId contractId, SubjectName subjectName,
155             RuleName ruleName) {
156         return InstanceIdentifier.builder(Tenants.class)
157             .child(Tenant.class, new TenantKey(tenantId))
158             .child(Policy.class)
159             .child(Contract.class, new ContractKey(contractId))
160             .child(Subject.class, new SubjectKey(subjectName))
161             .child(Rule.class, new RuleKey(ruleName))
162             .build();
163     }
164
165     public static InstanceIdentifier<ActionInstance> actionInstanceIid(TenantId tenantId, ActionName actionName) {
166         return InstanceIdentifier.builder(Tenants.class)
167             .child(Tenant.class, new TenantKey(tenantId))
168             .child(Policy.class)
169             .child(SubjectFeatureInstances.class)
170             .child(ActionInstance.class, new ActionInstanceKey(actionName))
171             .build();
172     }
173
174     public static InstanceIdentifier<ClassifierInstance> classifierInstanceIid(TenantId tenantId,
175             ClassifierName classifierName) {
176         return InstanceIdentifier.builder(Tenants.class)
177             .child(Tenant.class, new TenantKey(tenantId))
178             .child(Policy.class)
179             .child(SubjectFeatureInstances.class)
180             .child(ClassifierInstance.class, new ClassifierInstanceKey(classifierName))
181             .build();
182     }
183
184     public static InstanceIdentifier<ClassifierDefinition> classifierDefinitionIid(
185             ClassifierDefinitionId classifierDefinitionId) {
186         return InstanceIdentifier.builder(SubjectFeatureDefinitions.class)
187             .child(ClassifierDefinition.class, new ClassifierDefinitionKey(classifierDefinitionId))
188             .build();
189     }
190
191     public static InstanceIdentifier<ActionDefinition> actionDefinitionIid(ActionDefinitionId actionDefinitionId) {
192         return InstanceIdentifier.builder(SubjectFeatureDefinitions.class)
193             .child(ActionDefinition.class, new ActionDefinitionKey(actionDefinitionId))
194             .build();
195     }
196
197     public static InstanceIdentifier<ClassifierRef> classifierRefIid(TenantId tenantId, ContractId contractId,
198             SubjectName subjectName, RuleName ruleName, ClassifierName classifierRefName) {
199         return InstanceIdentifier.builder(Tenants.class)
200             .child(Tenant.class, new TenantKey(tenantId))
201             .child(Policy.class)
202             .child(Contract.class, new ContractKey(contractId))
203             .child(Subject.class, new SubjectKey(subjectName))
204             .child(Rule.class, new RuleKey(ruleName))
205             .child(ClassifierRef.class, new ClassifierRefKey(classifierRefName))
206             .build();
207     }
208
209     public static InstanceIdentifier<L2FloodDomain> l2FloodDomainIid(TenantId tenantId, L2FloodDomainId l2FloodDomainId) {
210         return InstanceIdentifier.builder(Tenants.class)
211             .child(Tenant.class, new TenantKey(tenantId))
212             .child(ForwardingContext.class)
213             .child(L2FloodDomain.class, new L2FloodDomainKey(l2FloodDomainId))
214             .build();
215     }
216
217     public static InstanceIdentifier<L2BridgeDomain> l2BridgeDomainIid(TenantId tenantId,
218             L2BridgeDomainId l2BridgeDomainId) {
219         return InstanceIdentifier.builder(Tenants.class)
220             .child(Tenant.class, new TenantKey(tenantId))
221             .child(ForwardingContext.class)
222             .child(L2BridgeDomain.class, new L2BridgeDomainKey(l2BridgeDomainId))
223             .build();
224     }
225
226     public static InstanceIdentifier<L3Context> l3ContextIid(TenantId tenantId, L3ContextId l3ContextId) {
227         return InstanceIdentifier.builder(Tenants.class)
228             .child(Tenant.class, new TenantKey(tenantId))
229             .child(ForwardingContext.class)
230             .child(L3Context.class, new L3ContextKey(l3ContextId))
231             .build();
232     }
233
234     /**
235      * Get the {@link Endpoint} {@link InstanceIdentifier} based on the {@link EndpointKey}
236      * @param endpointKey The {@link EndpointKey} of a particular {@link Endpoint}
237      * @return The {@link InstanceIdentifier} of the {@link Endpoint}
238      */
239     public static InstanceIdentifier<Endpoint> endpointIid(EndpointKey endpointKey) {
240         return InstanceIdentifier.builder(Endpoints.class).child(Endpoint.class, endpointKey).build();
241     }
242
243     public static InstanceIdentifier<Endpoint> endpointIid(L2BridgeDomainId l2Context, MacAddress macAddress) {
244         return IidFactory.endpointIid(new EndpointKey(l2Context, macAddress));
245     }
246
247     public static InstanceIdentifier<EndpointL3> l3EndpointIid(L3ContextId l3Context, IpAddress ipAddress) {
248         return InstanceIdentifier.builder(Endpoints.class)
249             .child(EndpointL3.class, new EndpointL3Key(ipAddress, l3Context))
250             .build();
251     }
252
253     public static InstanceIdentifier<EndpointL3> l3EndpointsIidWildcard() {
254         return InstanceIdentifier.builder(Endpoints.class)
255             .child(EndpointL3.class)
256             .build();
257     }
258
259     public static InstanceIdentifier<EndpointL3Prefix> endpointL3PrefixIid(L3ContextId l3Context, IpPrefix ipPrefix) {
260         return InstanceIdentifier.builder(Endpoints.class)
261             .child(EndpointL3Prefix.class, new EndpointL3PrefixKey(ipPrefix, l3Context))
262             .build();
263     }
264
265     public static InstanceIdentifier<Endpoints> endpointsIidWildcard() {
266         return ENDPOINTS_IID;
267     }
268
269     public static InstanceIdentifier<Subnet> subnetIid(TenantId tenantId, SubnetId subnetId) {
270         return InstanceIdentifier.builder(Tenants.class)
271             .child(Tenant.class, new TenantKey(tenantId))
272             .child(ForwardingContext.class)
273             .child(Subnet.class, new SubnetKey(subnetId))
274             .build();
275     }
276
277     public static InstanceIdentifier<FollowedEndpointGroup> followedEndpointgroupIid(RendererName rendererName,
278             TenantId tenantId, EndpointGroupId epgId) {
279         return InstanceIdentifier.builder(Renderers.class)
280             .child(Renderer.class, new RendererKey(rendererName))
281             .child(Interests.class)
282             .child(FollowedTenants.class)
283             .child(FollowedTenant.class, new FollowedTenantKey(tenantId))
284             .child(FollowedEndpointGroup.class, new FollowedEndpointGroupKey(epgId))
285             .build();
286     }
287
288 }