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