Bug 5540 - PortConvertor, MatchConvertor
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / cases / OfToSalPbbIsidCase.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, 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
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.cases;
10
11 import java.util.Optional;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.openflowplugin.api.OFConstants;
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.data.MatchResponseConvertorData;
16 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.PbbIsidCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.pbb.isid._case.PbbIsid;
22
23 public class OfToSalPbbIsidCase extends ConvertorCase<PbbIsidCase, MatchBuilder, MatchResponseConvertorData> {
24     public OfToSalPbbIsidCase() {
25         super(PbbIsidCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3);
26     }
27
28     @Override
29     public Optional<MatchBuilder> process(@Nonnull PbbIsidCase source, MatchResponseConvertorData data) {
30         final MatchBuilder matchBuilder = data.getMatchBuilder();
31         final ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = data.getProtocolMatchFieldsBuilder();
32
33         PbbIsid pbbIsid = source.getPbbIsid();
34
35         if (pbbIsid != null) {
36             PbbBuilder pbbBuilder = new PbbBuilder();
37             pbbBuilder.setPbbIsid(pbbIsid.getIsid());
38             byte[] mask = pbbIsid.getMask();
39
40             if (mask != null) {
41                 pbbBuilder.setPbbMask(ByteUtil.bytesToUnsignedMedium(mask));
42             }
43
44             protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
45             matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
46         }
47
48         return Optional.of(matchBuilder);
49     }
50 }