HONEYCOMB-118: extend classifer model to support node names.
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / VppClassifierHoneycombWriterFactory.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.ACL_ID;
20
21 import com.google.inject.Inject;
22 import com.google.inject.name.Named;
23 import io.fd.honeycomb.translate.impl.write.GenericListWriter;
24 import io.fd.honeycomb.translate.v3po.vppclassifier.ClassifySessionWriter;
25 import io.fd.honeycomb.translate.v3po.vppclassifier.ClassifyTableWriter;
26 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
27 import io.fd.honeycomb.translate.write.WriterFactory;
28 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
29 import javax.annotation.Nonnull;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifier;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.classify.table.base.attributes.ClassifySession;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.ClassifyTable;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.openvpp.jvpp.core.future.FutureJVppCore;
35
36 public final class VppClassifierHoneycombWriterFactory implements WriterFactory {
37
38     public static final InstanceIdentifier<ClassifyTable> CLASSIFY_TABLE_ID =
39             InstanceIdentifier.create(VppClassifier.class).child(ClassifyTable.class);
40
41     public static final InstanceIdentifier<ClassifySession> CLASSIFY_SESSION_ID =
42             CLASSIFY_TABLE_ID.child(ClassifySession.class);
43
44     private final FutureJVppCore jvpp;
45     private final VppClassifierContextManager classifyTableContext;
46
47     @Inject
48     public VppClassifierHoneycombWriterFactory(@Nonnull final FutureJVppCore jvpp,
49                                                @Named("classify-table-context") @Nonnull final VppClassifierContextManager classifyTableContext) {
50         this.jvpp = jvpp;
51         this.classifyTableContext = classifyTableContext;
52     }
53
54     @Override
55     public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
56         // Ordering here is: First create table, then create sessions and then assign as ACL
57         // ClassifyTable
58         registry.addBefore(
59                 new GenericListWriter<>(CLASSIFY_TABLE_ID, new ClassifyTableWriter(jvpp, classifyTableContext)),
60                 CLASSIFY_SESSION_ID);
61         //  ClassifyTableSession
62         registry.addBefore(
63                 new GenericListWriter<>(CLASSIFY_SESSION_ID, new ClassifySessionWriter(jvpp, classifyTableContext)),
64                 ACL_ID);
65     }
66 }