Added SFs, EP handling, Resolved Policy for IOVisorRenderer
[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.Capabilities;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.Interests;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedActionDefinition;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedClassifierDefinition;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.FollowedTenants;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.FollowedTenant;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.FollowedTenantKey;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.followed.tenant.FollowedEndpointGroup;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.followed.tenant.FollowedEndpointGroupKey;
88 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
89
90 public class IidFactory {
91
92     private IidFactory() {
93         throw new UnsupportedOperationException();
94     }
95
96     private static final InstanceIdentifier<Endpoints> ENDPOINTS_IID =
97             InstanceIdentifier.builder(Endpoints.class).build();
98
99     public static InstanceIdentifier<Tenant> tenantIid(TenantId id) {
100         return InstanceIdentifier.builder(Tenants.class).child(Tenant.class, new TenantKey(id)).build();
101     }
102
103     public static InstanceIdentifier<EndpointGroup> endpointGroupIid(TenantId tenantId, EndpointGroupId epgId) {
104         return InstanceIdentifier.builder(Tenants.class)
105             .child(Tenant.class, new TenantKey(tenantId))
106             .child(Policy.class)
107             .child(EndpointGroup.class, new EndpointGroupKey(epgId))
108             .build();
109     }
110
111     public static InstanceIdentifier<Contract> contractIid(TenantId tenantId, ContractId contractId) {
112         return InstanceIdentifier.builder(Tenants.class)
113             .child(Tenant.class, new TenantKey(tenantId))
114             .child(Policy.class)
115             .child(Contract.class, new ContractKey(contractId))
116             .build();
117     }
118
119     public static InstanceIdentifier<Subject> subjectIid(TenantId tenantId, ContractId contractId,
120             SubjectName subjectName) {
121         return InstanceIdentifier.builder(Tenants.class)
122             .child(Tenant.class, new TenantKey(tenantId))
123             .child(Policy.class)
124             .child(Contract.class, new ContractKey(contractId))
125             .child(Subject.class, new SubjectKey(subjectName))
126             .build();
127     }
128
129     public static InstanceIdentifier<ProviderNamedSelector> providerNamedSelectorIid(TenantId tenantId,
130             EndpointGroupId epgId, SelectorName providerSelectorName) {
131         return InstanceIdentifier.builder(Tenants.class)
132             .child(Tenant.class, new TenantKey(tenantId))
133             .child(Policy.class)
134             .child(EndpointGroup.class, new EndpointGroupKey(epgId))
135             .child(ProviderNamedSelector.class, new ProviderNamedSelectorKey(providerSelectorName))
136             .build();
137     }
138
139     public static InstanceIdentifier<ConsumerNamedSelector> consumerNamedSelectorIid(TenantId tenantId,
140             EndpointGroupId epgId, SelectorName consumerSelectorName) {
141         return InstanceIdentifier.builder(Tenants.class)
142             .child(Tenant.class, new TenantKey(tenantId))
143             .child(Policy.class)
144             .child(EndpointGroup.class, new EndpointGroupKey(epgId))
145             .child(ConsumerNamedSelector.class, new ConsumerNamedSelectorKey(consumerSelectorName))
146             .build();
147     }
148
149     public static InstanceIdentifier<Clause> clauseIid(TenantId tenantId, ContractId contractId,
150             ClauseName clauseName) {
151         return InstanceIdentifier.builder(Tenants.class)
152             .child(Tenant.class, new TenantKey(tenantId))
153             .child(Policy.class)
154             .child(Contract.class, new ContractKey(contractId))
155             .child(Clause.class, new ClauseKey(clauseName))
156             .build();
157     }
158
159     public static InstanceIdentifier<Rule> ruleIid(TenantId tenantId, ContractId contractId, SubjectName subjectName,
160             RuleName ruleName) {
161         return InstanceIdentifier.builder(Tenants.class)
162             .child(Tenant.class, new TenantKey(tenantId))
163             .child(Policy.class)
164             .child(Contract.class, new ContractKey(contractId))
165             .child(Subject.class, new SubjectKey(subjectName))
166             .child(Rule.class, new RuleKey(ruleName))
167             .build();
168     }
169
170     public static InstanceIdentifier<ActionInstance> actionInstanceIid(TenantId tenantId, ActionName actionName) {
171         return InstanceIdentifier.builder(Tenants.class)
172             .child(Tenant.class, new TenantKey(tenantId))
173             .child(Policy.class)
174             .child(SubjectFeatureInstances.class)
175             .child(ActionInstance.class, new ActionInstanceKey(actionName))
176             .build();
177     }
178
179     public static InstanceIdentifier<ClassifierInstance> classifierInstanceIid(TenantId tenantId,
180             ClassifierName classifierName) {
181         return InstanceIdentifier.builder(Tenants.class)
182             .child(Tenant.class, new TenantKey(tenantId))
183             .child(Policy.class)
184             .child(SubjectFeatureInstances.class)
185             .child(ClassifierInstance.class, new ClassifierInstanceKey(classifierName))
186             .build();
187     }
188
189     public static InstanceIdentifier<ClassifierDefinition> classifierDefinitionIid(
190             ClassifierDefinitionId classifierDefinitionId) {
191         return InstanceIdentifier.builder(SubjectFeatureDefinitions.class)
192             .child(ClassifierDefinition.class, new ClassifierDefinitionKey(classifierDefinitionId))
193             .build();
194     }
195
196     public static InstanceIdentifier<ActionDefinition> actionDefinitionIid(ActionDefinitionId actionDefinitionId) {
197         return InstanceIdentifier.builder(SubjectFeatureDefinitions.class)
198             .child(ActionDefinition.class, new ActionDefinitionKey(actionDefinitionId))
199             .build();
200     }
201
202     public static InstanceIdentifier<ClassifierRef> classifierRefIid(TenantId tenantId, ContractId contractId,
203             SubjectName subjectName, RuleName ruleName, ClassifierName classifierRefName) {
204         return InstanceIdentifier.builder(Tenants.class)
205             .child(Tenant.class, new TenantKey(tenantId))
206             .child(Policy.class)
207             .child(Contract.class, new ContractKey(contractId))
208             .child(Subject.class, new SubjectKey(subjectName))
209             .child(Rule.class, new RuleKey(ruleName))
210             .child(ClassifierRef.class, new ClassifierRefKey(classifierRefName))
211             .build();
212     }
213
214     public static InstanceIdentifier<L2FloodDomain> l2FloodDomainIid(TenantId tenantId,
215             L2FloodDomainId l2FloodDomainId) {
216         return InstanceIdentifier.builder(Tenants.class)
217             .child(Tenant.class, new TenantKey(tenantId))
218             .child(ForwardingContext.class)
219             .child(L2FloodDomain.class, new L2FloodDomainKey(l2FloodDomainId))
220             .build();
221     }
222
223     public static InstanceIdentifier<L2BridgeDomain> l2BridgeDomainIid(TenantId tenantId,
224             L2BridgeDomainId l2BridgeDomainId) {
225         return InstanceIdentifier.builder(Tenants.class)
226             .child(Tenant.class, new TenantKey(tenantId))
227             .child(ForwardingContext.class)
228             .child(L2BridgeDomain.class, new L2BridgeDomainKey(l2BridgeDomainId))
229             .build();
230     }
231
232     public static InstanceIdentifier<L3Context> l3ContextIid(TenantId tenantId, L3ContextId l3ContextId) {
233         return InstanceIdentifier.builder(Tenants.class)
234             .child(Tenant.class, new TenantKey(tenantId))
235             .child(ForwardingContext.class)
236             .child(L3Context.class, new L3ContextKey(l3ContextId))
237             .build();
238     }
239
240     /**
241      * Get the {@link Endpoint} {@link InstanceIdentifier} based on the {@link EndpointKey}
242      *
243      * @param endpointKey The {@link EndpointKey} of a particular {@link Endpoint}
244      * @return The {@link InstanceIdentifier} of the {@link Endpoint}
245      */
246     public static InstanceIdentifier<Endpoint> endpointIid(EndpointKey endpointKey) {
247         return InstanceIdentifier.builder(Endpoints.class).child(Endpoint.class, endpointKey).build();
248     }
249
250     public static InstanceIdentifier<Endpoint> endpointIid(L2BridgeDomainId l2Context, MacAddress macAddress) {
251         return IidFactory.endpointIid(new EndpointKey(l2Context, macAddress));
252     }
253
254     public static InstanceIdentifier<EndpointL3> l3EndpointIid(EndpointL3Key endpointL3Key) {
255         return InstanceIdentifier.builder(Endpoints.class).child(EndpointL3.class, endpointL3Key).build();
256     }
257
258     public static InstanceIdentifier<EndpointL3> l3EndpointIid(L3ContextId l3Context, IpAddress ipAddress) {
259         return IidFactory.l3EndpointIid(new EndpointL3Key(ipAddress, l3Context));
260     }
261
262     public static InstanceIdentifier<EndpointL3> l3EndpointsIidWildcard() {
263         return InstanceIdentifier.builder(Endpoints.class).child(EndpointL3.class).build();
264     }
265
266     public static InstanceIdentifier<EndpointL3Prefix> endpointL3PrefixIid(L3ContextId l3Context, IpPrefix ipPrefix) {
267         return InstanceIdentifier.builder(Endpoints.class)
268             .child(EndpointL3Prefix.class, new EndpointL3PrefixKey(ipPrefix, l3Context))
269             .build();
270     }
271
272     public static InstanceIdentifier<Endpoints> endpointsIidWildcard() {
273         return ENDPOINTS_IID;
274     }
275
276     public static InstanceIdentifier<Subnet> subnetIid(TenantId tenantId, SubnetId subnetId) {
277         return InstanceIdentifier.builder(Tenants.class)
278             .child(Tenant.class, new TenantKey(tenantId))
279             .child(ForwardingContext.class)
280             .child(Subnet.class, new SubnetKey(subnetId))
281             .build();
282     }
283
284     public static InstanceIdentifier<FollowedEndpointGroup> followedEndpointgroupIid(RendererName rendererName,
285             TenantId tenantId, EndpointGroupId epgId) {
286         return InstanceIdentifier.builder(Renderers.class)
287             .child(Renderer.class, new RendererKey(rendererName))
288             .child(Interests.class)
289             .child(FollowedTenants.class)
290             .child(FollowedTenant.class, new FollowedTenantKey(tenantId))
291             .child(FollowedEndpointGroup.class, new FollowedEndpointGroupKey(epgId))
292             .build();
293     }
294
295     public static InstanceIdentifier<SupportedActionDefinition> supportedActionDefinitionIidWildcard() {
296         return InstanceIdentifier.builder(Renderers.class)
297             .child(Renderer.class)
298             .child(Capabilities.class)
299             .child(SupportedActionDefinition.class)
300             .build();
301     }
302
303     public static InstanceIdentifier<SupportedClassifierDefinition> supportedClassifierDefinitionIidWildcard() {
304         return InstanceIdentifier.builder(Renderers.class)
305             .child(Renderer.class)
306             .child(Capabilities.class)
307             .child(SupportedClassifierDefinition.class)
308             .build();
309     }
310 }