Bug-6562: Support add-path in base BGP NLRI
[bgpcep.git] / bgp / evpn / src / main / java / org / opendaylight / protocol / bgp / evpn / impl / extended / communities / DefaultGatewayExtCom.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 package org.opendaylight.protocol.bgp.evpn.impl.extended.communities;
9
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
13 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
14 import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractOpaqueExtendedCommunity;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171207._default.gateway.extended.community.DefaultGatewayExtendedCommunityBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171207.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171207.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
19
20 public final class DefaultGatewayExtCom extends AbstractOpaqueExtendedCommunity {
21     private static final int SUBTYPE = 13;
22     private static final int RESERVED = 6;
23
24     @Override
25     public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
26         Preconditions.checkArgument(buffer.readableBytes() == RESERVED, "Wrong length of array of bytes. Passed: %s .", buffer.readableBytes());
27         buffer.skipBytes(RESERVED);
28         return new DefaultGatewayExtendedCommunityCaseBuilder().setDefaultGatewayExtendedCommunity(
29             new DefaultGatewayExtendedCommunityBuilder().build()).build();
30     }
31
32     @Override
33     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
34         Preconditions.checkArgument(extendedCommunity instanceof DefaultGatewayExtendedCommunityCase,
35             "The extended community %s is not DefaultGatewayExtendedCommunityCase type.", extendedCommunity);
36         byteAggregator.writeZero(RESERVED);
37     }
38
39     @Override
40     public int getSubType() {
41         return SUBTYPE;
42     }
43 }