e006813904a220da947c59ad970498ae3b118a5c
[bgpcep.git] / pcep / pcc-mock / src / main / java / org / opendaylight / protocol / pcep / pcc / mock / protocol / PCCServerPeerProposal.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.pcc.mock.protocol;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.math.BigInteger;
13 import java.net.InetSocketAddress;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.protocol.pcep.PCEPPeerProposal;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs3;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs3Builder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.lsp.db.version.tlv.LspDbVersionBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
20
21 public class PCCServerPeerProposal implements PCEPPeerProposal {
22     private boolean isAfterReconnection;
23     private final BigInteger dbVersion;
24
25     public PCCServerPeerProposal(@Nonnull final BigInteger dbVersion) {
26         this.dbVersion = dbVersion;
27     }
28
29     @Override
30     public void setPeerSpecificProposal(@Nonnull final InetSocketAddress address, @Nonnull final TlvsBuilder openBuilder) {
31         requireNonNull(address);
32         final LspDbVersionBuilder lspDbVersionBuilder = new LspDbVersionBuilder();
33         if (this.isAfterReconnection) {
34             lspDbVersionBuilder.setLspDbVersionValue(this.dbVersion);
35         } else {
36             this.isAfterReconnection = true;
37         }
38         openBuilder.addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(lspDbVersionBuilder.build()).build());
39     }
40 }