Merge "Move adsal into its own subdirectory."
[controller.git] / opendaylight / adsal / 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 final class Utils {
25
26     private Utils() { //prevent instantiation
27         throw new AssertionError();
28     }
29     static String getOFErrorString(OFError error) {
30         // Handle VENDOR extension errors here
31         if (error.getErrorType() == V6Error.NICIRA_VENDOR_ERRORTYPE) {
32             V6Error er = new V6Error(error);
33             byte[] b = error.getError();
34             ByteBuffer bb = ByteBuffer.allocate(b.length);
35             bb.put(b);
36             bb.rewind();
37             er.readFrom(bb);
38             return er.toString();
39         }
40
41         // Handle OF1.0 errors here
42         OFErrorType et = OFErrorType.values()[0xffff & error.getErrorType()];
43         String errorStr = "Error : " + et.toString();
44         switch (et) {
45         case OFPET_HELLO_FAILED:
46             OFHelloFailedCode hfc = OFHelloFailedCode.values()[0xffff & error
47                     .getErrorCode()];
48             errorStr += " " + hfc.toString();
49             break;
50         case OFPET_BAD_REQUEST:
51             OFBadRequestCode brc = OFBadRequestCode.values()[0xffff & error
52                     .getErrorCode()];
53             errorStr += " " + brc.toString();
54             break;
55         case OFPET_BAD_ACTION:
56             OFBadActionCode bac = OFBadActionCode.values()[0xffff & error
57                     .getErrorCode()];
58             errorStr += " " + bac.toString();
59             break;
60         case OFPET_FLOW_MOD_FAILED:
61             OFFlowModFailedCode fmfc = OFFlowModFailedCode.values()[0xffff & error
62                     .getErrorCode()];
63             errorStr += " " + fmfc.toString();
64             break;
65         case OFPET_PORT_MOD_FAILED:
66             OFPortModFailedCode pmfc = OFPortModFailedCode.values()[0xffff & error
67                     .getErrorCode()];
68             errorStr += " " + pmfc.toString();
69             break;
70         case OFPET_QUEUE_OP_FAILED:
71             OFQueueOpFailedCode qofc = OFQueueOpFailedCode.values()[0xffff & error
72                     .getErrorCode()];
73             errorStr += " " + qofc.toString();
74             break;
75         default:
76             break;
77         }
78         return errorStr;
79     }
80 }