Bump upstreams
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / AbstractMacAddressFilterEntrySerializer.java
1 /*
2  * Copyright (c) 2019 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.serialization.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.rev130715.IetfYangUtil;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.MacAddressFilter;
15
16 public abstract class AbstractMacAddressFilterEntrySerializer<E extends MacAddressFilter>
17     extends AbstractMatchEntrySerializer<E, MacAddress> {
18
19     protected AbstractMacAddressFilterEntrySerializer(final int oxmClassCode, final int oxmFieldCode) {
20         super(new ConstantHeaderWriter<>(oxmClassCode, oxmFieldCode, EncodeConstants.MAC_ADDRESS_LENGTH));
21     }
22
23     @Override
24     protected final MacAddress extractEntryMask(final E entry) {
25         return entry.getMask();
26     }
27
28     @Override
29     protected final void serializeEntry(final E entry, final MacAddress mask, final ByteBuf outBuffer) {
30         writeMacAddress(entry.getAddress(), outBuffer);
31         if (mask != null) {
32             writeMask(IetfYangUtil.macAddressBytes(mask), outBuffer, EncodeConstants.MAC_ADDRESS_LENGTH);
33         }
34     }
35 }