Merge remote-tracking branch 'liblldp/master'
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / match / Icmpv4CodeEntryDeserializer.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.model.match.types.rev131026.match.Icmpv4MatchBuilder;
15
16 public class Icmpv4CodeEntryDeserializer extends AbstractMatchEntryDeserializer {
17
18     @Override
19     public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
20         processHeader(message);
21         final short code = message.readUnsignedByte();
22
23         if (Objects.isNull(builder.getIcmpv4Match())) {
24             builder.setIcmpv4Match(new Icmpv4MatchBuilder()
25                     .setIcmpv4Code(code)
26                     .build());
27         } else if (Objects.isNull(builder.getIcmpv4Match().getIcmpv4Code())) {
28             builder.setIcmpv4Match(new Icmpv4MatchBuilder(builder.getIcmpv4Match())
29                     .setIcmpv4Code(code)
30                     .build());
31         } else {
32             throwErrorOnMalformed(builder, "icmpv4Match", "icmpv4Code");
33         }
34     }
35
36 }