4b815bf35c47c385d6a0ce340e530a4e34ba8f6e
[hc2vpp.git] /
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.samples.interfaces.mapping;
18
19 import com.google.common.collect.Lists;
20 import com.google.inject.Inject;
21 import io.fd.honeycomb.samples.interfaces.mapping.cfgattrs.InterfacesPluginConfiguration;
22 import io.fd.honeycomb.translate.write.WriteContext;
23 import java.util.ArrayList;
24 import javax.annotation.Nonnull;
25 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.interfaces.Interface;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * This is a sample class representing common resource for readers and writers to access the lower layer
32  */
33 public final class LowerLayerAccess {
34
35     private static final Logger LOG = LoggerFactory.getLogger(LowerLayerAccess.class);
36
37     @Inject
38     public LowerLayerAccess(@Nonnull final InterfacesPluginConfiguration configuration) {
39         LOG.info("Creating lower layer access with configuration: {}", configuration);
40     }
41
42     public void writeInterface(final InstanceIdentifier<Interface> id, final Interface dataAfter,
43                                final WriteContext writeContext) {
44         LOG.info("Writing interface: {}. to {}", dataAfter, id);
45         // This is where actual write/propagation happens
46         dataAfter.getMtu();
47     }
48
49     public void deleteInterface(final InstanceIdentifier<Interface> id, final Interface dataBefore,
50                                 final WriteContext writeContext) {
51         LOG.info("Deleting interface: {}. to {}", dataBefore, id);
52         final String ifcToBeDeleted = id.firstKeyOf(Interface.class).getInterfaceId().getValue();
53         // This is where actual write/propagation happens
54     }
55
56     public long getTotalPacketsForInterface(final String ifcName) {
57         return 500L;
58     }
59
60     public long getDroppedPacketsForIfc(final String ifcName) {
61         return 50L;
62     }
63
64     public ArrayList<String> getAllInterfaceNames() {
65         return Lists.newArrayList("ifc1", "ifc2");
66     }
67
68     public int getMtuForInterface(final String ifcName) {
69         return 66;
70     }
71 }