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 / CtZoneConvertor.java
1 /*
2  * Copyright (c) 2015 Hewlett-Packard Enterprise 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.openflowplugin.extension.vendor.nicira.convertor.match;
10
11 import com.google.common.base.Optional;
12
13 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
14 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
15 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
16 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
17 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStatsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtZoneGrouping;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtZoneKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZone;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZoneBuilder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
36
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.zone.grouping.CtZoneValuesBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValue;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValueBuilder;
40
41 /**
42  * @author Aswin Suryanarayanan.
43  */
44
45 public class CtZoneConvertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see
51      * org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava#convert
52      * (org.opendaylight.yangtools.yang.binding.DataContainer,
53      * org.opendaylight.openflowplugin.extension.api.path.AugmentationPath)
54      */
55     @Override
56     public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
57         CtZoneCaseValue ctZoneCaseValue = ((CtZoneCaseValue) input.getMatchEntryValue());
58         NxmNxCtZoneBuilder ctZoneBuilder = new NxmNxCtZoneBuilder();
59         ctZoneBuilder.setCtZone(ctZoneCaseValue.getCtZoneValues().getCtZone());
60         return resolveAugmentation(ctZoneBuilder.build(), path,
61                 NxmNxCtZoneKey.class);
62     }
63
64     /*
65      * (non-Javadoc)
66      *
67      * @see
68      * org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava#convert
69      * (org
70      * .opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general
71      * .rev140714.general.extension.grouping.Extension)
72      */
73     @Override
74     public MatchEntry convert(Extension extension) {
75         Optional<NxmNxCtZoneGrouping> matchGrouping = MatchUtil.ctZoneResolver.getExtension(extension);
76         if (!matchGrouping.isPresent()) {
77             throw new CodecPreconditionException(extension);
78         }
79         CtZoneCaseValueBuilder ctZoneCaseValueBuilder = new CtZoneCaseValueBuilder();
80         CtZoneValuesBuilder ctZoneValuesBuilder = new CtZoneValuesBuilder();
81         ctZoneValuesBuilder.setCtZone(matchGrouping.get().getNxmNxCtZone().getCtZone());
82         ctZoneCaseValueBuilder.setCtZoneValues(ctZoneValuesBuilder.build());
83         MatchEntryBuilder ofMatch = MatchUtil
84                 .createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn
85                                                 .opendaylight.openflowjava.nx.match.rev140421.NxmNxCtZone.class,
86                                                 Nxm1Class.class, ctZoneCaseValueBuilder.build());
87         return ofMatch.build();
88     }
89
90     private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmNxCtZone value,
91                                                                    MatchPath path, Class<? extends ExtensionKey> key) {
92         switch (path) {
93             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH:
94                 return new ExtensionAugment<>(NxAugMatchNotifUpdateFlowStats.class,
95                         new NxAugMatchNotifUpdateFlowStatsBuilder().setNxmNxCtZone(value).build(), key);
96             case RPCFLOWSSTATISTICS_FLOWANDSTATISTICSMAPLIST_MATCH:
97                 return new ExtensionAugment<>(NxAugMatchRpcGetFlowStats.class,
98                         new NxAugMatchRpcGetFlowStatsBuilder().setNxmNxCtZone(value).build(), key);
99             case PACKETRECEIVED_MATCH:
100                 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
101                         .setNxmNxCtZone(value).build(), key);
102             case SWITCHFLOWREMOVED_MATCH:
103                 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
104                         new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxCtZone(value).build(), key);
105             default:
106                 throw new CodecPreconditionException(path);
107         }
108     }
109 }