MVPN RFC6514 Extendend communities
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / four / octect / as / specific / RouteOrigin4OctectASEcHandler.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.parser.impl.message.update.extended.communities.four.octect.as.specific;
10
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.bgp.parser.spi.extended.community.Abstract4OctetAsExtendedCommunity;
14 import org.opendaylight.protocol.bgp.parser.spi.extended.community.FourOctAsCommonECUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteOriginExtendedCommunityCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
19
20 public final class RouteOrigin4OctectASEcHandler extends Abstract4OctetAsExtendedCommunity {
21     private static final int SUBTYPE = 3;
22
23     @Override
24     public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) {
25         return new As4RouteOriginExtendedCommunityCaseBuilder()
26                 .setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder()
27                         .setAs4SpecificCommon(FourOctAsCommonECUtil.parseCommon(body)).build()).build();
28     }
29
30     @Override
31     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
32         Preconditions.checkArgument(extendedCommunity instanceof As4RouteOriginExtendedCommunityCase,
33                 "The extended community %s is not As4RouteOriginExtendedCommunityCase type.",
34                 extendedCommunity);
35         FourOctAsCommonECUtil.serializeCommon(((As4RouteOriginExtendedCommunityCase) extendedCommunity)
36                 .getAs4RouteOriginExtendedCommunity().getAs4SpecificCommon(), body);
37     }
38
39     @Override
40     public int getSubType() {
41         return SUBTYPE;
42     }
43 }