2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.flowspec.extended.communities;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
14 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
15 import org.opendaylight.protocol.util.Ipv4Util;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.ipv4.extended.community.RedirectIpv4;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.ipv4.extended.community.RedirectIpv4Builder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectIpv4ExtendedCommunityCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
20 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
22 public class RedirectIpv4EcHandler implements ExtendedCommunityParser, ExtendedCommunitySerializer {
23 private static final int TYPE = 129;
24 private static final int SUBTYPE = 8;
27 public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
28 checkArgument(extendedCommunity instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
29 .flowspec.rev180329.RedirectIpv4ExtendedCommunity,
30 "The extended community %s is not RedirectIpv4ExtendedCommunityCase type.", extendedCommunity);
31 final RedirectIpv4 redirect = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec
32 .rev180329.RedirectIpv4ExtendedCommunity) extendedCommunity).getRedirectIpv4();
33 Ipv4Util.writeIpv4Address(redirect.getGlobalAdministrator(), byteAggregator);
34 ByteBufUtils.writeOrZero(byteAggregator, redirect.getLocalAdministrator());
38 public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
39 return new RedirectIpv4ExtendedCommunityCaseBuilder()
40 .setRedirectIpv4(new RedirectIpv4Builder()
41 .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
42 .setLocalAdministrator(ByteBufUtils.readUint16(buffer))
48 public int getType(final boolean isTransitive) {
53 public int getSubType() {