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