RPC opendaylight-direct-statistics:get-flow-statistics not taking nicira
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / main / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / EncapEthDstConvertor.java
1 /**
2  * Copyright (c) 2015 Intel, 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 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
9
10 import com.google.common.base.Optional;
11 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
12 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
13 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
14 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
15 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.encap.eth.dst.grouping.EncapEthDstValuesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EncapEthDstCaseValue;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EncapEthDstCaseValueBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxEncapEthDstGrouping;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxEncapEthDstKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.encap.eth.dst.grouping.NxmNxEncapEthDst;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.encap.eth.dst.grouping.NxmNxEncapEthDstBuilder;
36 import org.opendaylight.yangtools.yang.binding.Augmentation;
37
38 public class EncapEthDstConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
39
40     /*
41      * (non-Javadoc)
42      * 
43      * @see
44      * org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava#convert
45      * (org.opendaylight.yangtools.yang.binding.DataContainer,
46      * org.opendaylight.openflowplugin.extension.api.path.AugmentationPath)
47      */
48     @Override
49     public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
50         EncapEthDstCaseValue encapEthDstCaseValue = ((EncapEthDstCaseValue) input.getMatchEntryValue());
51         return resolveAugmentation(new NxmNxEncapEthDstBuilder().setMacAddress(encapEthDstCaseValue.getEncapEthDstValues().getMacAddress()).build(), path,
52                 NxmNxEncapEthDstKey.class);
53     }
54
55     private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmNxEncapEthDst value,
56                                                                                            MatchPath path, Class<? extends ExtensionKey> key) {
57         switch (path) {
58             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH:
59                 return new ExtensionAugment<>(NxAugMatchNotifUpdateFlowStats.class,
60                         new NxAugMatchNotifUpdateFlowStatsBuilder().setNxmNxEncapEthDst(value).build(), key);
61             case RPCFLOWSSTATISTICS_FLOWANDSTATISTICSMAPLIST_MATCH:
62                 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
63                         new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxEncapEthDst(value).build(), key);
64             case PACKETRECEIVED_MATCH:
65                 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
66                         .setNxmNxEncapEthDst(value).build(), key);
67             case SWITCHFLOWREMOVED_MATCH:
68                 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
69                         new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxEncapEthDst(value).build(), key);
70             default:
71                 throw new CodecPreconditionException(path);
72         }
73     }
74
75     /*
76      * (non-Javadoc)
77      * 
78      * @see
79      * org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava#convert
80      * (org
81      * .opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general
82      * .rev140714.general.extension.grouping.Extension)
83      */
84     @Override
85     public MatchEntry convert(Extension extension) {
86         Optional<NxmNxEncapEthDstGrouping> matchGrouping = MatchUtil.encapEthDstResolver.getExtension(extension);
87         if (!matchGrouping.isPresent()) {
88             throw new CodecPreconditionException(extension);
89         }
90         MacAddress macAddress = matchGrouping.get().getNxmNxEncapEthDst().getMacAddress();
91         EncapEthDstCaseValueBuilder encapEthDstCaseValueBuilder = new EncapEthDstCaseValueBuilder();
92         encapEthDstCaseValueBuilder.setEncapEthDstValues(new EncapEthDstValuesBuilder()
93                 .setMacAddress(macAddress).build());
94         return MatchUtil.createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxEncapEthDst.class,
95                 Nxm1Class.class,
96                 encapEthDstCaseValueBuilder.build()).build();
97     }
98
99 }