77a39e904ad16505a9ac573879236fd6c4c51dd9
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / Utils.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.protocol_plugin.openflow.internal;
11
12 import org.openflow.protocol.OFError;
13 import org.openflow.protocol.OFError.OFBadActionCode;
14 import org.openflow.protocol.OFError.OFBadRequestCode;
15 import org.openflow.protocol.OFError.OFErrorType;
16 import org.openflow.protocol.OFError.OFFlowModFailedCode;
17 import org.openflow.protocol.OFError.OFHelloFailedCode;
18 import org.openflow.protocol.OFError.OFPortModFailedCode;
19 import org.openflow.protocol.OFError.OFQueueOpFailedCode;
20
21 public abstract class Utils {
22     public static String getOFErrorString(OFError error) {
23         OFErrorType et = OFErrorType.values()[0xffff & error.getErrorType()];
24         String errorStr = "Error : " + et.toString();
25         switch (et) {
26         case OFPET_HELLO_FAILED:
27             OFHelloFailedCode hfc = OFHelloFailedCode.values()[0xffff & error
28                     .getErrorCode()];
29             errorStr += " " + hfc.toString();
30             break;
31         case OFPET_BAD_REQUEST:
32             OFBadRequestCode brc = OFBadRequestCode.values()[0xffff & error
33                     .getErrorCode()];
34             errorStr += " " + brc.toString();
35             break;
36         case OFPET_BAD_ACTION:
37             OFBadActionCode bac = OFBadActionCode.values()[0xffff & error
38                     .getErrorCode()];
39             errorStr += " " + bac.toString();
40             break;
41         case OFPET_FLOW_MOD_FAILED:
42             OFFlowModFailedCode fmfc = OFFlowModFailedCode.values()[0xffff & error
43                     .getErrorCode()];
44             errorStr += " " + fmfc.toString();
45             break;
46         case OFPET_PORT_MOD_FAILED:
47             OFPortModFailedCode pmfc = OFPortModFailedCode.values()[0xffff & error
48                     .getErrorCode()];
49             errorStr += " " + pmfc.toString();
50             break;
51         case OFPET_QUEUE_OP_FAILED:
52             OFQueueOpFailedCode qofc = OFQueueOpFailedCode.values()[0xffff & error
53                     .getErrorCode()];
54             errorStr += " " + qofc.toString();
55             break;
56         default:
57             break;
58         }
59         return errorStr;
60     }
61 }