Add Match entry deserializers
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / match / VlanPcpEntryDeserializer.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 io.netty.buffer.ByteBuf;
12 import java.util.Objects;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
16
17 public class VlanPcpEntryDeserializer extends AbstractMatchEntryDeserializer {
18
19     @Override
20     public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
21         processHeader(message);
22         final short pcp = message.readUnsignedByte();
23
24         if (Objects.isNull(builder.getVlanMatch())) {
25             builder.setVlanMatch(new VlanMatchBuilder()
26                     .setVlanPcp(new VlanPcp(pcp))
27                     .build());
28         } else if (Objects.nonNull(builder.getVlanMatch().getVlanPcp())) {
29             builder.setVlanMatch(new VlanMatchBuilder(builder.getVlanMatch())
30                     .setVlanPcp(new VlanPcp(pcp))
31                     .build());
32         } else {
33             throwErrorOnMalformed(builder, "vlanMatch");
34         }
35     }
36
37 }