Code clean up
[bgpcep.git] / bgp / extensions / evpn / src / main / java / org / opendaylight / protocol / bgp / evpn / impl / esi / types / AbstractEsiType.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.protocol.bgp.evpn.impl.esi.types;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.opendaylight.protocol.bgp.evpn.spi.EsiParser;
14 import org.opendaylight.protocol.bgp.evpn.spi.EsiSerializer;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
17
18 abstract class AbstractEsiType implements EsiParser, EsiSerializer {
19     private static final int BODY_LENGTH = 9;
20     static final int ZERO_BYTE = 1;
21     static final int MAC_ADDRESS_LENGTH = 6;
22
23     @Override
24     public final void serializeEsi(final Esi esi, final ByteBuf buffer) {
25         final ByteBuf body = Unpooled.buffer(BODY_LENGTH);
26         serializeBody(esi, body);
27         buffer.writeByte(getType().getIntValue());
28         buffer.writeBytes(body);
29     }
30
31     protected abstract void serializeBody(Esi esi, ByteBuf buffer);
32
33     protected abstract EsiType getType();
34 }