2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
10 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
11 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
12 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
13 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
14 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nshc._3.grouping.Nshc3ValuesBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc3CaseValue;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc3CaseValueBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketInBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemovedBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNshc3Grouping;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNshc3Key;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._3.grouping.NxmNxNshc3;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._3.grouping.NxmNxNshc3Builder;
32 import org.opendaylight.yangtools.yang.binding.Augmentation;
34 import com.google.common.base.Optional;
36 public class Nshc3Convertor implements ConvertorToOFJava<MatchEntry>, ConvertorFromOFJava<MatchEntry, MatchPath> {
38 public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
39 Nshc3CaseValue nsc3CaseValue = ((Nshc3CaseValue) input.getMatchEntryValue());
41 return resolveAugmentation(new NxmNxNshc3Builder().setValue(nsc3CaseValue.getNshc3Values().getNshc()).build(), path,
45 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(NxmNxNshc3 value,
46 MatchPath path, Class<? extends ExtensionKey> key) {
48 case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH:
49 return new ExtensionAugment<>(NxAugMatchNotifUpdateFlowStats.class,
50 new NxAugMatchNotifUpdateFlowStatsBuilder().setNxmNxNshc3(value).build(), key);
51 case PACKETRECEIVED_MATCH:
52 return new ExtensionAugment<>(NxAugMatchNotifPacketIn.class, new NxAugMatchNotifPacketInBuilder()
53 .setNxmNxNshc3(value).build(), key);
54 case SWITCHFLOWREMOVED_MATCH:
55 return new ExtensionAugment<>(NxAugMatchNotifSwitchFlowRemoved.class,
56 new NxAugMatchNotifSwitchFlowRemovedBuilder().setNxmNxNshc3(value).build(), key);
58 throw new CodecPreconditionException(path);
63 public MatchEntry convert(Extension extension) {
64 Optional<NxmNxNshc3Grouping> matchGrouping = MatchUtil.nsc3Resolver.getExtension(extension);
65 if (!matchGrouping.isPresent()) {
66 throw new CodecPreconditionException(extension);
68 Long value = matchGrouping.get().getNxmNxNshc3().getValue();
69 Nshc3CaseValueBuilder nsc3CaseValueBuilder = new Nshc3CaseValueBuilder();
70 nsc3CaseValueBuilder.setNshc3Values(new Nshc3ValuesBuilder()
71 .setNshc(value).build());
74 return MatchUtil.createDefaultMatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxNshc3.class,
76 nsc3CaseValueBuilder.build()).build();