23fc2e314b49583c547da99f1b837c0b4b16a7fc
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / AclWriterFactory.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.translate.v3po;
18
19 import static io.fd.honeycomb.translate.v3po.InterfacesWriterFactory.IETF_ACL_ID;
20 import static io.fd.honeycomb.translate.v3po.SubinterfaceAugmentationWriterFactory.SUBIF_IETF_ACL_ID;
21
22 import com.google.common.collect.Sets;
23 import io.fd.honeycomb.translate.impl.write.GenericListWriter;
24 import io.fd.honeycomb.translate.v3po.interfaces.acl.IetfAclWriter;
25 import io.fd.honeycomb.translate.write.WriterFactory;
26 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.Acl;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntries;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.Ace;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.Actions;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.ace.Matches;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.DestinationPortRange;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160708.acl.transport.header.fields.SourcePortRange;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37
38 public final class AclWriterFactory implements WriterFactory {
39
40     public static final InstanceIdentifier<Acl> ACL_ID =
41         InstanceIdentifier.create(AccessLists.class).child(Acl.class);
42
43     @Override
44     public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
45
46         final InstanceIdentifier<Acl> aclIdRelative = InstanceIdentifier.create(Acl.class);
47
48         final InstanceIdentifier<Ace> aceId = aclIdRelative.child(AccessListEntries.class).child(Ace.class);
49         final InstanceIdentifier<Actions> actionsId = aceId.child(Actions.class);
50         final InstanceIdentifier<Matches> matchesId = aceId.child(Matches.class);
51         final InstanceIdentifier<SourcePortRange> srcPortId = matchesId.child((Class)SourcePortRange.class);
52         final InstanceIdentifier<DestinationPortRange> dstPortId = matchesId.child((Class)DestinationPortRange.class);
53
54         registry.subtreeAddBefore(Sets.newHashSet(aceId, actionsId, matchesId, srcPortId, dstPortId),
55             new GenericListWriter<>(ACL_ID, new IetfAclWriter()),
56             Sets.newHashSet(IETF_ACL_ID, SUBIF_IETF_ACL_ID));
57     }
58 }