Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / OxmDeserializerHelper.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.util.EncodeConstants;
13 import org.opendaylight.openflowjava.util.ByteBufUtils;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
15
16 /**
17  * @author michal.polkorab
18  *
19  */
20 public final class OxmDeserializerHelper {
21
22     private OxmDeserializerHelper() {
23         throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
24     }
25
26     /**
27      * Converts binary data into binary mask (for match entries)
28      * @param input input ByteBuf
29      * @param matchEntryLength mask length
30      * @return binary mask
31      */
32     public static byte[] convertMask(ByteBuf input, int matchEntryLength) {
33         byte[] mask = new byte[matchEntryLength];
34         input.readBytes(mask);
35         return mask;
36     }
37
38     /**
39      * Converts binary data into mac address
40      * @param input input ByteBuf
41      * @return mac address
42      */
43     public static MacAddress convertMacAddress(ByteBuf input) {
44         byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
45         input.readBytes(address);
46         return new MacAddress(ByteBufUtils.macAddressToString(address));
47     }
48 }