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
9 package org.opendaylight.protocol.pcep.segment.routing02;
11 import io.netty.buffer.ByteBuf;
12 import java.util.List;
13 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07PCUpdateRequestMessageParser;
14 import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
15 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.Lsp;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcupd.message.pcupd.message.Updates;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcupd.message.pcupd.message.UpdatesBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcupd.message.pcupd.message.updates.PathBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs6;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs7;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
27 public class SrPcUpdMessageParser extends Stateful07PCUpdateRequestMessageParser {
29 public SrPcUpdMessageParser(ObjectRegistry registry) {
34 protected void serializeUpdate(Updates update, ByteBuf buffer) {
35 if (isSegmentRoutingPath(update.getSrp())) {
36 serializeObject(update.getSrp(), buffer);
37 if (update.getLsp() != null) {
38 serializeObject(update.getLsp(), buffer);
40 final Ero srEro = update.getPath().getEro();
42 serializeObject(srEro, buffer);
45 super.serializeUpdate(update, buffer);
50 protected Updates getValidUpdates(List<Object> objects, List<Message> errors) {
51 if (objects.get(0) instanceof Srp && isSegmentRoutingPath((Srp) objects.get(0))) {
52 boolean isValid = true;
53 final Srp srp = (Srp) objects.get(0);
54 final UpdatesBuilder builder = new UpdatesBuilder();
57 if (objects.get(0) instanceof Lsp) {
58 builder.setLsp((Lsp) objects.get(0));
61 errors.add(createErrorMsg(PCEPErrors.LSP_MISSING));
65 final Object obj = objects.get(0);
66 if (obj instanceof Ero) {
67 final Ero ero = (Ero) obj;
68 final PCEPErrors error = SrEroUtil.validateSrEroSubobjects(ero);
70 errors.add(createErrorMsg(error));
73 builder.setPath(new PathBuilder().setEro(ero).build());
77 errors.add(createErrorMsg(PCEPErrors.ERO_MISSING));
81 return builder.build();
85 return super.getValidUpdates(objects, errors);
88 private boolean isSegmentRoutingPath(final Srp srp) {
89 if (srp != null && srp.getTlvs() != null) {
90 return SrEroUtil.isPst(srp.getTlvs().getAugmentation(Tlvs6.class))
91 || SrEroUtil.isPst(srp.getTlvs().getAugmentation(Tlvs7.class));