Determine preferred node/port from PCRI
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / port / ClientPreference.java
1 /*
2  * Copyright (c) 2024 Smartoptics 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
9 package org.opendaylight.transportpce.pce.networkanalyzer.port;
10
11 import java.util.Map;
12 import java.util.Set;
13
14 public class ClientPreference implements Preference {
15
16     Map<String, Set<String>> nodePortPreference;
17
18     public ClientPreference(Map<String, Set<String>> nodePortPreference) {
19         this.nodePortPreference = nodePortPreference;
20     }
21
22     @Override
23     public boolean isPreferredPort(String node, String portName) {
24
25         //If there is no preferred port registered for the node, it means
26         //the client has no preference regarding the node.
27         //Therefore, we'll treat the node as it was preferred to
28         //prevent it from NOT being used.
29         return !nodePortPreference.containsKey(node) || nodePortPreference.get(node).contains(portName);
30
31     }
32
33 }