Checkstyle enforcer
[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 java.nio.ByteBuffer;
13
14 import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Error;
15 import org.openflow.protocol.OFError;
16 import org.openflow.protocol.OFError.OFBadActionCode;
17 import org.openflow.protocol.OFError.OFBadRequestCode;
18 import org.openflow.protocol.OFError.OFErrorType;
19 import org.openflow.protocol.OFError.OFFlowModFailedCode;
20 import org.openflow.protocol.OFError.OFHelloFailedCode;
21 import org.openflow.protocol.OFError.OFPortModFailedCode;
22 import org.openflow.protocol.OFError.OFQueueOpFailedCode;
23
24 public abstract class Utils {
25     public static String getOFErrorString(OFError error) {
26         // Handle VENDOR extension errors here
27         if (error.getErrorType() == V6Error.NICIRA_VENDOR_ERRORTYPE) {
28             V6Error er = new V6Error(error);
29             byte[] b = error.getError();
30             ByteBuffer bb = ByteBuffer.allocate(b.length);
31             bb.put(b);
32             bb.rewind();
33             er.readFrom(bb);
34             return er.toString();
35         }
36
37         // Handle OF1.0 errors here
38         OFErrorType et = OFErrorType.values()[0xffff & error.getErrorType()];
39         String errorStr = "Error : " + et.toString();
40         switch (et) {
41         case OFPET_HELLO_FAILED:
42             OFHelloFailedCode hfc = OFHelloFailedCode.values()[0xffff & error
43                     .getErrorCode()];
44             errorStr += " " + hfc.toString();
45             break;
46         case OFPET_BAD_REQUEST:
47             OFBadRequestCode brc = OFBadRequestCode.values()[0xffff & error
48                     .getErrorCode()];
49             errorStr += " " + brc.toString();
50             break;
51         case OFPET_BAD_ACTION:
52             OFBadActionCode bac = OFBadActionCode.values()[0xffff & error
53                     .getErrorCode()];
54             errorStr += " " + bac.toString();
55             break;
56         case OFPET_FLOW_MOD_FAILED:
57             OFFlowModFailedCode fmfc = OFFlowModFailedCode.values()[0xffff & error
58                     .getErrorCode()];
59             errorStr += " " + fmfc.toString();
60             break;
61         case OFPET_PORT_MOD_FAILED:
62             OFPortModFailedCode pmfc = OFPortModFailedCode.values()[0xffff & error
63                     .getErrorCode()];
64             errorStr += " " + pmfc.toString();
65             break;
66         case OFPET_QUEUE_OP_FAILED:
67             OFQueueOpFailedCode qofc = OFQueueOpFailedCode.values()[0xffff & error
68                     .getErrorCode()];
69             errorStr += " " + qofc.toString();
70             break;
71         default:
72             break;
73         }
74         return errorStr;
75     }
76 }