989fbae766e502654d906f07ef65e39f35054ce0
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / four / octect / as / specific / Generic4OctASEcHandler.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.BGPDocumentedException;
14 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
15 import org.opendaylight.protocol.bgp.parser.spi.extended.community.Abstract4OctetAsExtendedCommunity;
16 import org.opendaylight.protocol.bgp.parser.spi.extended.community.FourOctAsCommonECUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4GenericSpecExtendedCommunityCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.generic.spec.extended.community._case.As4GenericSpecExtendedCommunityBuilder;
21
22 public final class Generic4OctASEcHandler extends Abstract4OctetAsExtendedCommunity {
23     private static final int SUBTYPE = 4;
24
25     @Override
26     public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) throws BGPDocumentedException, BGPParsingException {
27         return new As4GenericSpecExtendedCommunityCaseBuilder().setAs4GenericSpecExtendedCommunity(new As4GenericSpecExtendedCommunityBuilder()
28             .setAs4SpecificCommon(FourOctAsCommonECUtil.parseCommon(body)).build()).build();
29     }
30
31     @Override
32     public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
33         Preconditions.checkArgument(extendedCommunity instanceof As4GenericSpecExtendedCommunityCase,
34             "The extended community %s is not As4GenericSpecExtendedCommunityCase type.", extendedCommunity);
35         FourOctAsCommonECUtil.serializeCommon(((As4GenericSpecExtendedCommunityCase) extendedCommunity).getAs4GenericSpecExtendedCommunity()
36             .getAs4SpecificCommon(), body);
37     }
38
39     @Override
40     public int getSubType() {
41         return SUBTYPE;
42     }
43 }