2 * Copyright (c) 2014 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.linkstate.impl.tlvs;
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.OspfRouteType;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.prefix._case.PrefixDescriptors;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
18 public final class OspfRouteTlvParser implements LinkstateTlvParser<OspfRouteType>,
19 LinkstateTlvParser.LinkstateTlvSerializer<OspfRouteType> {
20 public static final QName OSPF_ROUTE_TYPE_QNAME = QName.create(PrefixDescriptors.QNAME, "ospf-route-type").intern();
21 public static final NodeIdentifier OSPF_ROUTE_NID = NodeIdentifier.create(OspfRouteTlvParser.OSPF_ROUTE_TYPE_QNAME);
23 private static final int OSPF_ROUTE_TYPE = 264;
26 public void serializeTlvBody(final OspfRouteType tlv, final ByteBuf body) {
27 body.writeByte(tlv.getIntValue());
31 public int getType() {
32 return OSPF_ROUTE_TYPE;
36 public OspfRouteType parseTlvBody(final ByteBuf value) {
37 return OspfRouteType.forValue(value.readUnsignedByte());
41 public QName getTlvQName() {
42 return OSPF_ROUTE_TYPE_QNAME;
45 public static OspfRouteType serializeModel(final ContainerNode prefixDesc) {
46 final var ospfRoute = prefixDesc.childByArg(OSPF_ROUTE_NID);
47 return ospfRoute == null ? null : OspfRouteType.forValue(domOspfRouteTypeValue((String) ospfRoute.body()));
51 private static int domOspfRouteTypeValue(final String ospfRouteType) {
52 return switch (ospfRouteType) {
53 case "intra-area" -> OspfRouteType.IntraArea.getIntValue();
54 case "inter-area" -> OspfRouteType.InterArea.getIntValue();
55 case "external1" -> OspfRouteType.External1.getIntValue();
56 case "external2" -> OspfRouteType.External2.getIntValue();
57 case "nssa1" -> OspfRouteType.Nssa1.getIntValue();
58 case "nssa2" -> OspfRouteType.Nssa2.getIntValue();