Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / AbstractOxmIpv4AddressDeserializer.java
1 /*
2  * Copyright (c) 2013 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.openflowjava.protocol.impl.deserialization.match;
9
10 import io.netty.buffer.ByteBuf;
11
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
13 import org.opendaylight.openflowjava.util.ByteBufUtils;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
20
21 /**
22  * @author michal.polkorab
23  *
24  */
25 public abstract class AbstractOxmIpv4AddressDeserializer extends AbstractOxmMatchEntryDeserializer
26         implements OFDeserializer<MatchEntries> {
27
28     @Override
29     public MatchEntries deserialize(final ByteBuf input) {
30         MatchEntriesBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
31         addIpv4AddressAugmentation(builder, input);
32         if (builder.isHasMask()) {
33             OxmMaskDeserializer.addMaskAugmentation(builder, input, EncodeConstants.SIZE_OF_INT_IN_BYTES);
34         }
35         return builder.build();
36     }
37
38     private static void addIpv4AddressAugmentation(final MatchEntriesBuilder builder, final ByteBuf input) {
39         Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
40         ipv4AddressBuilder.setIpv4Address(new Ipv4Address(ByteBufUtils.readIpv4Address(input)));
41         builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
42     }
43 }