Merge "Remove old drop-test module and files."
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / match / PbbEntryDeserializer.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.impl.protocol.deserialization.match;
10
11 import java.util.Objects;
12
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
16
17 import io.netty.buffer.ByteBuf;
18
19 public class PbbEntryDeserializer extends AbstractMatchEntryDeserializer {
20
21     @Override
22     public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
23         final boolean hasMask = processHeader(message);
24         final long pbb = message.readUnsignedMedium();
25         final PbbBuilder pbbBuilder = new PbbBuilder()
26             .setPbbIsid(pbb);
27
28         if (hasMask) {
29             pbbBuilder.setPbbMask((long) message.readUnsignedMedium());
30         }
31
32         if (Objects.isNull(builder.getProtocolMatchFields())) {
33             builder.setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
34                     .setPbb(pbbBuilder.build())
35                     .build());
36         } else if (Objects.isNull(builder.getProtocolMatchFields().getPbb())) {
37             builder.setProtocolMatchFields(new ProtocolMatchFieldsBuilder(builder.getProtocolMatchFields())
38                     .setPbb(pbbBuilder.build())
39                     .build());
40         } else {
41             throwErrorOnMalformed(builder, "protocolMatchFields", "pbb");
42         }
43     }
44
45 }