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.protocol.util.ByteBufWriteUtil;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.OspfRouteType;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.PrefixDescriptors;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
19 public final class OspfRouteTlvParser implements LinkstateTlvParser<OspfRouteType>,
20 LinkstateTlvParser.LinkstateTlvSerializer<OspfRouteType> {
22 public static final QName OSPF_ROUTE_TYPE_QNAME =
23 QName.create(PrefixDescriptors.QNAME.getModule(), "ospf-route-type");
24 public static final NodeIdentifier OSPF_ROUTE_NID = new NodeIdentifier(OspfRouteTlvParser.OSPF_ROUTE_TYPE_QNAME);
25 private static final int OSPF_ROUTE_TYPE = 264;
28 public void serializeTlvBody(final OspfRouteType tlv, final ByteBuf body) {
29 ByteBufWriteUtil.writeUnsignedByte((short) tlv.getIntValue(), body);
33 public int getType() {
34 return OSPF_ROUTE_TYPE;
38 public OspfRouteType parseTlvBody(final ByteBuf value) {
39 return OspfRouteType.forValue(value.readUnsignedByte());
43 public QName getTlvQName() {
44 return OSPF_ROUTE_TYPE_QNAME;
47 public static OspfRouteType serializeModel(final ContainerNode prefixDesc) {
48 return prefixDesc.getChild(OSPF_ROUTE_NID).map(
49 dataContainerChild -> OspfRouteType.forValue(domOspfRouteTypeValue((String) dataContainerChild.getValue())))
54 private static int domOspfRouteTypeValue(final String ospfRouteType) {
55 switch (ospfRouteType) {
57 return OspfRouteType.IntraArea.getIntValue();
59 return OspfRouteType.InterArea.getIntValue();
61 return OspfRouteType.External1.getIntValue();
63 return OspfRouteType.External2.getIntValue();
65 return OspfRouteType.Nssa1.getIntValue();
67 return OspfRouteType.Nssa2.getIntValue();