Performacne improvements via adding a netty-based openflowj and openflow plugin;...
[controller.git] / opendaylight / protocol_plugins / openflow_netty / 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
28         /*
29         if (error.getErrorType() == V6Error.NICIRA_VENDOR_ERRORTYPE) {
30             V6Error er = new V6Error(error);
31             byte[] b = error.getError();
32             ByteBuffer bb = ByteBuffer.allocate(b.length);
33             bb.put(b);
34             bb.rewind();
35             er.readFrom(bb);
36             return er.toString();
37         }
38         */
39
40         // Handle OF1.0 errors here
41         OFErrorType et = OFErrorType.values()[0xffff & error.getErrorType()];
42         String errorStr = "Error : " + et.toString();
43         switch (et) {
44         case OFPET_HELLO_FAILED:
45             OFHelloFailedCode hfc = OFHelloFailedCode.values()[0xffff & error
46                     .getErrorCode()];
47             errorStr += " " + hfc.toString();
48             break;
49         case OFPET_BAD_REQUEST:
50             OFBadRequestCode brc = OFBadRequestCode.values()[0xffff & error
51                     .getErrorCode()];
52             errorStr += " " + brc.toString();
53             break;
54         case OFPET_BAD_ACTION:
55             OFBadActionCode bac = OFBadActionCode.values()[0xffff & error
56                     .getErrorCode()];
57             errorStr += " " + bac.toString();
58             break;
59         case OFPET_FLOW_MOD_FAILED:
60             OFFlowModFailedCode fmfc = OFFlowModFailedCode.values()[0xffff & error
61                     .getErrorCode()];
62             errorStr += " " + fmfc.toString();
63             break;
64         case OFPET_PORT_MOD_FAILED:
65             OFPortModFailedCode pmfc = OFPortModFailedCode.values()[0xffff & error
66                     .getErrorCode()];
67             errorStr += " " + pmfc.toString();
68             break;
69         case OFPET_QUEUE_OP_FAILED:
70             OFQueueOpFailedCode qofc = OFQueueOpFailedCode.values()[0xffff & error
71                     .getErrorCode()];
72             errorStr += " " + qofc.toString();
73             break;
74         default:
75             break;
76         }
77         return errorStr;
78     }
79 }