1 package org.onosproject.provider.pcep.tunnel.impl;
3 import java.util.Collection;
4 import java.util.Collections;
5 import java.util.HashSet;
7 import java.util.concurrent.ConcurrentHashMap;
9 import org.apache.felix.scr.annotations.Activate;
10 import org.apache.felix.scr.annotations.Deactivate;
11 import org.onlab.packet.IpAddress;
12 import org.onosproject.pcep.controller.PccId;
13 import org.onosproject.pcep.controller.PcepClient;
14 import org.onosproject.pcep.controller.PcepClientController;
15 import org.onosproject.pcep.controller.PcepClientListener;
16 import org.onosproject.pcep.controller.PcepEventListener;
17 import org.onosproject.pcep.controller.driver.PcepAgent;
18 import org.onosproject.pcepio.protocol.PcepMessage;
19 import org.onosproject.pcepio.protocol.PcepVersion;
21 import com.google.common.collect.Sets;
23 public class PcepClientControllerAdapter implements PcepClientController {
25 protected ConcurrentHashMap<PccId, PcepClient> connectedClients =
26 new ConcurrentHashMap<PccId, PcepClient>();
28 protected PcepClientAgent agent = new PcepClientAgent();
29 protected Set<PcepClientListener> pcepClientListener = new HashSet<>();
31 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
34 public void activate() {
38 public void deactivate() {
42 public Collection<PcepClient> getClients() {
43 return connectedClients.values();
47 public PcepClient getClient(PccId pccId) {
48 //return connectedClients.get(pccIpAddress);
49 PcepClientAdapter pc = new PcepClientAdapter();
50 pc.init(PccId.pccId(IpAddress.valueOf(0xac000001)), PcepVersion.PCEP_1);
55 public void addListener(PcepClientListener listener) {
56 if (!pcepClientListener.contains(listener)) {
57 this.pcepClientListener.add(listener);
62 public void removeListener(PcepClientListener listener) {
63 this.pcepClientListener.remove(listener);
67 public void addEventListener(PcepEventListener listener) {
68 pcepEventListener.add(listener);
72 public void removeEventListener(PcepEventListener listener) {
73 pcepEventListener.remove(listener);
77 public void writeMessage(PccId pccId, PcepMessage msg) {
78 this.getClient(pccId).sendMessage(msg);
82 public void processClientMessage(PccId pccId, PcepMessage msg) {
84 PcepClient pc = getClient(pccId);
86 switch (msg.getType()) {
92 //log.debug("Sending Keep Alive Message to {" + pccIpAddress.toString() + "}");
93 pc.sendMessage(Collections.singletonList(pc.factory().buildKeepaliveMsg().build()));
95 case PATH_COMPUTATION_REQUEST:
97 case PATH_COMPUTATION_REPLY:
104 //log.debug("Sending Close Message to { }", pccIpAddress.toString());
105 pc.sendMessage(Collections.singletonList(pc.factory().buildCloseMsg().build()));
108 for (PcepEventListener l : pcepEventListener) {
109 l.handleMessage(pccId, msg);
113 for (PcepEventListener l : pcepEventListener) {
114 l.handleMessage(pccId, msg);
118 for (PcepEventListener l : pcepEventListener) {
119 l.handleMessage(pccId, msg);
134 public void closeConnectedClients() {
136 for (PccId id : connectedClients.keySet()) {
138 pc.disconnectClient();
143 * Implementation of an Pcep Agent which is responsible for
144 * keeping track of connected clients and the state in which
147 public class PcepClientAgent implements PcepAgent {
150 public boolean addConnectedClient(PccId pccId, PcepClient pc) {
152 if (connectedClients.get(pccId) != null) {
155 connectedClients.put(pccId, pc);
156 for (PcepClientListener l : pcepClientListener) {
157 l.clientConnected(pccId);
164 public boolean validActivation(PccId pccId) {
165 if (connectedClients.get(pccId) == null) {
166 //log.error("Trying to activate client but is not in "
167 // + "connected switches: pccIp {}. Aborting ..", pccIpAddress.toString());
175 public void removeConnectedClient(PccId pccId) {
176 connectedClients.remove(pccId);
177 for (PcepClientListener l : pcepClientListener) {
178 //log.warn("removal for {}", pccIpAddress.toString());
179 l.clientDisconnected(pccId);
184 public void processPcepMessage(PccId pccId, PcepMessage m) {
185 processClientMessage(pccId, m);