e88a46ad280230b76aea4e471c77fa237ed24c51
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / match / Ipv6ExtHeaderEntryDeserializer.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 package org.opendaylight.openflowplugin.impl.protocol.deserialization.match;
9
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint16;
11
12 import io.netty.buffer.ByteBuf;
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.ipv6.match.fields.Ipv6ExtHeaderBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
17
18 public class Ipv6ExtHeaderEntryDeserializer extends AbstractMatchEntryDeserializer {
19     @Override
20     public void deserializeEntry(final ByteBuf message, final MatchBuilder builder) {
21         final boolean hasMask = processHeader(message);
22         final Ipv6ExtHeaderBuilder extHeaderBuilder = new Ipv6ExtHeaderBuilder()
23             .setIpv6Exthdr(readUint16(message));
24
25         if (hasMask) {
26             extHeaderBuilder.setIpv6ExthdrMask(readUint16(message));
27         }
28
29         if (builder.getLayer3Match() == null) {
30             builder.setLayer3Match(new Ipv6MatchBuilder()
31                     .setIpv6ExtHeader(extHeaderBuilder.build())
32                     .build());
33         } else if (builder.getLayer3Match() instanceof Ipv6Match
34                 && ((Ipv6Match) builder.getLayer3Match()).getIpv6ExtHeader() == null) {
35             final Ipv6Match match = (Ipv6Match) builder.getLayer3Match();
36             builder.setLayer3Match(new Ipv6MatchBuilder(match)
37                     .setIpv6ExtHeader(extHeaderBuilder.build())
38                     .build());
39         } else {
40             throwErrorOnMalformed(builder, "layer3Match", "ipv6ExtHeader");
41         }
42     }
43 }