blob: 2f519eca8dba542e3f205d56b76bbbfffc969667 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053016package org.onosproject.provider.pcep.tunnel.impl;
17
18import static org.junit.Assert.assertNotNull;
19
20import java.util.List;
21import java.util.concurrent.RejectedExecutionException;
22
23import org.jboss.netty.channel.Channel;
Priyanka Bd2b28882016-04-04 16:57:04 +053024import org.onosproject.pcep.controller.ClientCapability;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053025import org.onosproject.pcep.controller.PccId;
26import org.onosproject.pcep.controller.PcepClient;
27import org.onosproject.pcepio.protocol.PcepFactories;
28import org.onosproject.pcepio.protocol.PcepFactory;
29import org.onosproject.pcepio.protocol.PcepMessage;
30import org.onosproject.pcepio.protocol.PcepVersion;
31
Priyanka Bd2b28882016-04-04 16:57:04 +053032/**
33 * Representation of PCEP client adapter.
34 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053035public class PcepClientAdapter implements PcepClient {
36
37 private Channel channel;
38 protected String channelId;
39
40 private boolean connected;
41 private PccId pccId;
Priyanka Bd2b28882016-04-04 16:57:04 +053042 private ClientCapability capability;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053043
44 private PcepVersion pcepVersion;
Avantika-Huawei56c11842016-04-28 00:56:56 +053045 private boolean syncCompleted;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053046
Priyanka Bd2b28882016-04-04 16:57:04 +053047 /**
48 * Initialize instance with specified parameters.
49 *
50 * @param pccId PCC id
51 * @param pcepVersion PCEP message version
52 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053053 public void init(PccId pccId, PcepVersion pcepVersion) {
54 this.pccId = pccId;
55 this.pcepVersion = pcepVersion;
56 }
57
58 @Override
59 public final void disconnectClient() {
60 this.channel.close();
61 }
62
63 @Override
64 public final void sendMessage(PcepMessage m) {
65 }
66
67 @Override
68 public final void sendMessage(List<PcepMessage> msgs) {
69 try {
70 PcepMessage pcepMsg = msgs.get(0);
71 assertNotNull("PCEP MSG should be created.", pcepMsg);
72 } catch (RejectedExecutionException e) {
73 throw e;
74 }
75 }
76
77 @Override
78 public final boolean isConnected() {
79 return this.connected;
80 }
81
82 @Override
83 public String channelId() {
84 return channelId;
85 }
86
87 @Override
88 public final PccId getPccId() {
89 return this.pccId;
90 };
91
92 @Override
93 public final String getStringId() {
94 return this.pccId.toString();
95 }
96
97 @Override
98 public final void handleMessage(PcepMessage m) {
99 }
100
101 @Override
102 public boolean isOptical() {
103 return false;
104 }
105
106 @Override
107 public PcepFactory factory() {
108 return PcepFactories.getFactory(pcepVersion);
109 }
110
111 @Override
112 public final boolean isSyncComplete() {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530113 return syncCompleted;
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530114 }
115
116 @Override
117 public final void setIsSyncComplete(boolean value) {
Avantika-Huawei56c11842016-04-28 00:56:56 +0530118 syncCompleted = value;
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530119 }
Priyanka Bd2b28882016-04-04 16:57:04 +0530120
121 @Override
122 public void setCapability(ClientCapability capability) {
123 this.capability = capability;
124 }
125
126 @Override
127 public ClientCapability capability() {
128 return capability;
129 }
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530130}