Determine preferred node/port from PCRI
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / networkanalyzer / port / ClientPreferenceTest.java
1 /*
2  * Copyright © 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
12 import java.util.HashMap;
13 import java.util.Map;
14 import java.util.Set;
15 import org.junit.jupiter.api.Assertions;
16 import org.junit.jupiter.api.Test;
17
18 class ClientPreferenceTest {
19
20     @Test
21     void preferredPort_returnTrue() {
22
23         Map<String, Set<String>> nodePortPreference = new HashMap<>();
24         nodePortPreference.put("ROADM-B-SRG1", Set.of("SRG1-PP1-TXRX"));
25
26         Preference clientPreference = new ClientPreference(nodePortPreference);
27
28         Assertions.assertTrue(clientPreference.isPreferredPort("ROADM-B-SRG1", "SRG1-PP1-TXRX"));
29     }
30
31     /**
32      * The client prefer to use SRG1-PP1-TXRX on ROADM-B-SRG1.
33      * Therefore, preferredPort returns false on SRG1-PP2-TXRX.
34      */
35     @Test
36     void nonPreferredPort_returnFalse() {
37
38         Map<String, Set<String>> nodePortPreference = new HashMap<>();
39         nodePortPreference.put("ROADM-B-SRG1", Set.of("SRG1-PP1-TXRX"));
40
41         Preference clientPreference = new ClientPreference(nodePortPreference);
42
43         Assertions.assertFalse(clientPreference.isPreferredPort("ROADM-B-SRG1", "SRG1-PP2-TXRX"));
44     }
45
46     /**
47      * In this scenario ROADM-A-SRG1 is missing from the client preferred list.
48      * We treat this as the client has no opinion on what port
49      * to use on ROADM-A-SRG1. Meaning, as far as the client goes, all
50      * ports on ROADM-A-SRG1 are fine.
51      */
52     @Test
53     void nodeMissingInPreferredList_returnTrue() {
54
55         Map<String, Set<String>> nodePortPreference = new HashMap<>();
56         nodePortPreference.put("ROADM-B-SRG1", Set.of("SRG1-PP1-TXRX"));
57
58         Preference clientPreference = new ClientPreference(nodePortPreference);
59
60         Assertions.assertTrue(clientPreference.isPreferredPort("ROADM-A-SRG1", "SRG1-PP2-TXRX"));
61
62     }
63 }