0c0dac864a06204fcbdc60d83b37dfcdb7e00508
[onosfw.git] /
1 /*
2  * Copyright 2015 Open Networking Laboratory
3  *
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  */
16 package org.onosproject.segmentrouting.config;
17
18 import org.onosproject.net.DeviceId;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * NetworkConfigExceptions specifies a set of unchecked runtime exceptions that
24  * can be thrown by the {@link NetworkConfigManager}. It indicates errors that
25  * must be fixed in the config file before controller execution can proceed.
26  */
27 public class NetworkConfigException extends RuntimeException {
28
29     private static final long serialVersionUID = 4959684709803000652L;
30     protected static final Logger log = LoggerFactory
31             .getLogger(NetworkConfigException.class);
32
33     /**
34      * Exception for duplicate device identifier configuration.
35      */
36     public static class DuplicateDpid extends RuntimeException {
37         private static final long serialVersionUID = 5491113234592145335L;
38
39         public DuplicateDpid(DeviceId dpid) {
40             super();
41             log.error("Duplicate dpid found in switch-config Dpid:{}",
42                     dpid);
43         }
44     }
45
46     /**
47      * Exception for duplicate device name configuration.
48      */
49     public static class DuplicateName extends RuntimeException {
50         private static final long serialVersionUID = -4090171438031376129L;
51
52         public DuplicateName(String name) {
53             super();
54             log.error("Duplicate name found in switch-config name:{}", name);
55         }
56     }
57
58     /**
59      * Exception for unspecified device identifier for a switch.
60      */
61     public static class DpidNotSpecified extends RuntimeException {
62         private static final long serialVersionUID = -8494418855597117254L;
63
64         public DpidNotSpecified(String name) {
65             super();
66             log.error("Dpid not specified for switch-config name:{}", name);
67         }
68     }
69
70     /**
71      * Exception for unspecified device name for a switch.
72      */
73     public static class NameNotSpecified extends RuntimeException {
74         private static final long serialVersionUID = -3518881744110422891L;
75
76         public NameNotSpecified(DeviceId dpid) {
77             super();
78             log.error("Name not specified for switch-config dpid:{}",
79                     dpid);
80         }
81     }
82
83     /**
84      * Exception for unspecified device type for a switch.
85      */
86     public static class SwitchTypeNotSpecified extends RuntimeException {
87         private static final long serialVersionUID = 2527453336226053753L;
88
89         public SwitchTypeNotSpecified(DeviceId dpid) {
90             super();
91             log.error("Switch type not specified for switch-config dpid:{}",
92                     dpid);
93         }
94     }
95
96     /**
97      * Exception for unknown device type configured for a switch.
98      */
99     public static class UnknownSwitchType extends RuntimeException {
100         private static final long serialVersionUID = 7758418165512249170L;
101
102         public UnknownSwitchType(String type, String name) {
103             super();
104             log.error("Unknown switch type {} for switch name:{}", type, name);
105         }
106     }
107
108     /**
109      * Exception for missing required parameter configuration for a switch.
110      */
111     public static class ParamsNotSpecified extends RuntimeException {
112         private static final long serialVersionUID = 6247582323691265513L;
113
114         public ParamsNotSpecified(String name) {
115             super();
116             log.error("Params required - not specified for switch:{}", name);
117         }
118     }
119
120     /**
121      * Reserved for future use.
122      */
123     public static class LinkTypeNotSpecified extends RuntimeException {
124         private static final long serialVersionUID = -2089470389588542215L;
125
126         public LinkTypeNotSpecified(String dpid1, String dpid2) {
127             super();
128             log.error("Link type not specified for link-config between "
129                     + "dpid1:{} and dpid2:{}", dpid1, dpid2);
130         }
131     }
132
133     /**
134      * Reserved for future use.
135      */
136     public static class LinkDpidNotSpecified extends RuntimeException {
137         private static final long serialVersionUID = -5701825916378616004L;
138
139         public LinkDpidNotSpecified(String dpid1, String dpid2) {
140             super();
141             if (dpid1 == null) {
142                 log.error("nodeDpid1 not specified for link-config ");
143             }
144             if (dpid2 == null) {
145                 log.error("nodeDpid2 not specified for link-config ");
146             }
147         }
148     }
149
150     /**
151      * Reserved for future use.
152      */
153     public static class LinkForUnknownSwitchConfig extends RuntimeException {
154         private static final long serialVersionUID = -2910458439881964094L;
155
156         public LinkForUnknownSwitchConfig(String dpid) {
157             super();
158             log.error("Link configuration was specified for a switch-dpid {} "
159                     + "that has not been configured", dpid);
160         }
161     }
162
163     /**
164      * Reserved for future use.
165      */
166     public static class UnknownLinkType extends RuntimeException {
167         private static final long serialVersionUID = -5505376193106542305L;
168
169         public UnknownLinkType(String linktype, String dpid1, String dpid2) {
170             super();
171             log.error("unknown link type {} for links between dpid1:{} "
172                     + "and dpid2:{}", linktype, dpid1, dpid2);
173         }
174     }
175
176     /**
177      * Exception for generic configuration errors.
178      */
179     public static class ErrorConfig extends RuntimeException {
180         private static final long serialVersionUID = -2827406314700193147L;
181
182         public ErrorConfig(String errorMsg) {
183             super();
184             log.error(errorMsg);
185         }
186
187     }
188
189     /**
190      * Reserved for future use.
191      */
192     public static class SwitchDpidNotConverted extends RuntimeException {
193         private static final long serialVersionUID = 5640347104590170426L;
194
195         public SwitchDpidNotConverted(String name) {
196             super();
197             log.error("Switch dpid specified as a HexString {} does not match "
198                     + "with long value", name);
199         }
200     }
201
202     /**
203      * Reserved for future use.
204      */
205     public static class LinkDpidNotConverted extends RuntimeException {
206         private static final long serialVersionUID = 2397245646094080774L;
207
208         public LinkDpidNotConverted(String dpid1, String dpid2) {
209             log.error("Dpids expressed as HexStrings for links between dpid1:{} "
210                     + "and dpid2:{} do not match with long values", dpid1, dpid2);
211         }
212     }
213
214 }
215