47cc590655553a800ed4a489f9a295b0f6317414
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / PCEPErrorMapping.java
1 /*
2  * Copyright (c) 2013 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.spi;
9
10 import java.util.HashMap;
11 import java.util.Map;
12 import java.util.NoSuchElementException;
13
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Bidirectional mapping of {@link org.opendaylight.protocol.pcep.spi.PCEPErrors PCEPErrors} and
19  * {@link org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser.PCEPErrorIdentifier ErrorIdentifier}
20  */
21 public final class PCEPErrorMapping {
22
23         private static final Logger LOG = LoggerFactory.getLogger(PCEPErrorMapping.class);
24
25         /**
26          * Caret for combination of Error-type and Error-value
27          */
28         public static final class PCEPErrorIdentifier {
29                 public short type;
30                 public short value;
31
32                 private PCEPErrorIdentifier(final short type, final short value) {
33                         this.type = type;
34                         this.value = value;
35                 }
36
37                 @Override
38                 public int hashCode() {
39                         final int prime = 31;
40                         int result = 1;
41                         result = prime * result + this.type;
42                         result = prime * result + this.value;
43                         return result;
44                 }
45
46                 @Override
47                 public boolean equals(final java.lang.Object obj) {
48                         if (this == obj) {
49                                 return true;
50                         }
51                         if (obj == null) {
52                                 return false;
53                         }
54                         if (this.getClass() != obj.getClass()) {
55                                 return false;
56                         }
57                         final PCEPErrorIdentifier other = (PCEPErrorIdentifier) obj;
58                         if (this.type != other.type) {
59                                 return false;
60                         }
61                         if (this.value != other.value) {
62                                 return false;
63                         }
64                         return true;
65                 }
66
67                 @Override
68                 public String toString() {
69                         return "type " + this.type + " value " + this.value;
70                 }
71         }
72
73         private static final PCEPErrorMapping INSTANCE = new PCEPErrorMapping();
74
75         private final Map<PCEPErrors, PCEPErrorIdentifier> errorsMap = new HashMap<PCEPErrors, PCEPErrorIdentifier>();
76         private final Map<PCEPErrorIdentifier, PCEPErrors> errorIdsMap = new HashMap<PCEPErrorIdentifier, PCEPErrors>();
77
78         private PCEPErrorMapping() {
79                 this.fillIn();
80         }
81
82         private void fillIn() {
83                 this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 1), PCEPErrors.NON_OR_INVALID_OPEN_MSG);
84                 this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 2), PCEPErrors.NO_OPEN_BEFORE_EXP_OPENWAIT);
85                 this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 3), PCEPErrors.NON_ACC_NON_NEG_SESSION_CHAR);
86                 this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 4), PCEPErrors.NON_ACC_NEG_SESSION_CHAR);
87                 this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 5), PCEPErrors.SECOND_OPEN_MSG);
88                 this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 6), PCEPErrors.PCERR_NON_ACC_SESSION_CHAR);
89                 this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 7), PCEPErrors.NO_MSG_BEFORE_EXP_KEEPWAIT);
90                 this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 8), PCEPErrors.PCEP_VERSION_NOT_SUPPORTED);
91
92                 this.fillIn(new PCEPErrorIdentifier((short) 2, (short) 0), PCEPErrors.CAPABILITY_NOT_SUPPORTED);
93
94                 this.fillIn(new PCEPErrorIdentifier((short) 3, (short) 1), PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
95                 this.fillIn(new PCEPErrorIdentifier((short) 3, (short) 2), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
96
97                 this.fillIn(new PCEPErrorIdentifier((short) 4, (short) 1), PCEPErrors.NOT_SUPPORTED_OBJ_CLASS);
98                 this.fillIn(new PCEPErrorIdentifier((short) 4, (short) 2), PCEPErrors.NOT_SUPPORTED_OBJ_TYPE);
99
100                 this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 1), PCEPErrors.C_BIT_SET);
101                 this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 2), PCEPErrors.O_BIT_SET);
102                 this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 3), PCEPErrors.OF_NOT_ALLOWED);
103                 this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 4), PCEPErrors.OF_BIT_SET);
104                 this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 5), PCEPErrors.GCO_NOT_ALLOWED);
105                 this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 7), PCEPErrors.P2MP_COMPUTATION_NOT_ALLOWED);
106
107                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 1), PCEPErrors.RP_MISSING);
108                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 2), PCEPErrors.RRO_MISSING);
109                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 3), PCEPErrors.END_POINTS_MISSING);
110                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 8), PCEPErrors.LSP_MISSING);
111                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 9), PCEPErrors.ERO_MISSING);
112                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 10), PCEPErrors.SRP_MISSING);
113                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 11), PCEPErrors.LSP_IDENTIFIERS_TLV_MISSING);
114                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 12), PCEPErrors.DB_VERSION_TLV_MISSING);
115
116                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 13), PCEPErrors.LSP_CLEANUP_TLV_MISSING);
117                 this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 14), PCEPErrors.SYMBOLIC_PATH_NAME_MISSING);
118
119                 this.fillIn(new PCEPErrorIdentifier((short) 7, (short) 0), PCEPErrors.SYNC_PATH_COMP_REQ_MISSING);
120
121                 this.fillIn(new PCEPErrorIdentifier((short) 8, (short) 0), PCEPErrors.UNKNOWN_REQ_REF);
122
123                 this.fillIn(new PCEPErrorIdentifier((short) 9, (short) 0), PCEPErrors.ATTEMPT_2ND_SESSION);
124
125                 this.fillIn(new PCEPErrorIdentifier((short) 10, (short) 1), PCEPErrors.P_FLAG_NOT_SET);
126
127                 this.fillIn(new PCEPErrorIdentifier((short) 12, (short) 1), PCEPErrors.UNSUPPORTED_CT);
128                 this.fillIn(new PCEPErrorIdentifier((short) 12, (short) 2), PCEPErrors.INVALID_CT);
129                 this.fillIn(new PCEPErrorIdentifier((short) 12, (short) 3), PCEPErrors.CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS);
130
131                 this.fillIn(new PCEPErrorIdentifier((short) 15, (short) 1), PCEPErrors.INSUFFICIENT_MEMORY);
132                 this.fillIn(new PCEPErrorIdentifier((short) 15, (short) 2), PCEPErrors.GCO_NOT_SUPPORTED);
133
134                 this.fillIn(new PCEPErrorIdentifier((short) 16, (short) 1), PCEPErrors.CANNOT_SATISFY_P2MP_REQUEST_DUE_TO_INSUFFISIENT_MEMMORY);
135                 this.fillIn(new PCEPErrorIdentifier((short) 16, (short) 2), PCEPErrors.NOT_CAPPABLE_P2MP_COMPUTATION);
136
137                 this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 1), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT2);
138                 this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 2), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT3);
139                 this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 3), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT4);
140                 this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 4), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_INCONSISTENT_EP);
141
142                 this.fillIn(new PCEPErrorIdentifier((short) 18, (short) 1), PCEPErrors.P2MP_FRAGMENTATION_FAILRUE);
143
144                 this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 1), PCEPErrors.UPDATE_REQ_FOR_NON_LSP);
145                 this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 2), PCEPErrors.UPDATE_REQ_FOR_NO_STATEFUL);
146                 // TODO: value TBD
147                 this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 3), PCEPErrors.UNKNOWN_PLSP_ID);
148                 this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 4), PCEPErrors.LSP_LIMIT_EXCEEDED);
149
150                 this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 1), PCEPErrors.CANNOT_PROCESS_STATE_REPORT);
151                 this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 2), PCEPErrors.LSP_DB_VERSION_MISMATCH);
152                 this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 3), PCEPErrors.DB_VERSION_TLV_MISSING_WHEN_SYNC_ALLOWED);
153                 this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 5), PCEPErrors.CANNOT_COMPLETE_STATE_SYNC);
154
155                 this.fillIn(new PCEPErrorIdentifier((short) 23, (short) 1), PCEPErrors.USED_SYMBOLIC_PATH_NAME);
156         }
157
158         private void fillIn(final PCEPErrorIdentifier identifier, final PCEPErrors error) {
159                 this.errorsMap.put(error, identifier);
160                 this.errorIdsMap.put(identifier, error);
161         }
162
163         public PCEPErrorIdentifier getFromErrorsEnum(final PCEPErrors error) {
164                 final PCEPErrorIdentifier ei = this.errorsMap.get(error);
165                 if (ei == null) {
166                         LOG.debug("Unknown PCEPErrors type: {}.", error);
167                         throw new NoSuchElementException("Unknown PCEPErrors type: " + error);
168                 }
169                 return ei;
170         }
171
172         public PCEPErrors getFromErrorIdentifier(final PCEPErrorIdentifier identifier) {
173                 final PCEPErrors e = this.errorIdsMap.get(identifier);
174                 if (e == null) {
175                         LOG.debug("Unknown error type/value combination: {}.", identifier);
176                         throw new NoSuchElementException("Unknown error type/value combination: " + identifier);
177                 }
178                 return e;
179         }
180
181         public static PCEPErrorMapping getInstance() {
182                 return INSTANCE;
183         }
184 }