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.rsvp.parser.impl.te;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import io.netty.buffer.ByteBuf;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
16 import org.opendaylight.protocol.util.Ipv4Util;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.detour.object.detour.object.Ipv4DetourObject;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.detour.object.detour.object.Ipv4DetourObjectBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.detour.object.detour.object.ipv4.detour.object.Plr;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.detour.object.detour.object.ipv4.detour.object.PlrBuilder;
23 public final class DetourObjectIpv4Parser extends AbstractRSVPObjectParser {
25 public static final short CLASS_NUM = 63;
26 public static final short CTYPE = 7;
29 protected RsvpTeObject localParseObject(final ByteBuf byteBuf) {
30 final Ipv4DetourObjectBuilder ipv4Case = new Ipv4DetourObjectBuilder();
31 final List<Plr> plrList = new ArrayList<>();
32 while (byteBuf.isReadable()) {
33 final PlrBuilder plr = new PlrBuilder();
34 plr.setPlrId(Ipv4Util.noZoneAddressForByteBuf(byteBuf));
35 plr.setAvoidNode(Ipv4Util.noZoneAddressForByteBuf(byteBuf));
36 plrList.add(plr.build());
38 return ipv4Case.setPlr(plrList).build();
42 public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) {
43 checkArgument(teLspObject instanceof Ipv4DetourObject, "DetourObject is mandatory.");
44 final Ipv4DetourObject detourObject = (Ipv4DetourObject) teLspObject;
46 final List<Plr> list = detourObject.getPlr();
47 serializeAttributeHeader(list.size() * 2 * Ipv4Util.IP4_LENGTH, CLASS_NUM, CTYPE, byteAggregator);
48 for (final Plr plr : list) {
49 Ipv4Util.writeIpv4Address(plr.getPlrId(), byteAggregator);
50 Ipv4Util.writeIpv4Address(plr.getAvoidNode(), byteAggregator);