2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.openflow.md.core.translator;
10 import java.util.Collections;
11 import java.util.List;
12 import java.util.concurrent.CopyOnWriteArrayList;
14 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
15 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
16 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
17 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.errors.rev131116.ErrorType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * general support for errorMessage OF-API to MD-SAL translation
28 public abstract class AbstractErrorTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
30 protected static final Logger LOG = LoggerFactory.getLogger(AbstractErrorTranslator.class);
33 public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) {
34 if (msg instanceof ErrorMessage) {
35 ErrorMessage message = (ErrorMessage) msg;
36 List<DataObject> list = new CopyOnWriteArrayList<DataObject>();
37 if (LOG.isDebugEnabled()) {
38 String hexData = "n/a";
39 if (message.getData() != null) {
40 hexData = ByteUtil.bytesToHexstring(message.getData(), " ");
42 LOG.debug(" Error Message received: type={}[{}], code={}[{}], data=[{}] ", message.getType(),
43 message.getTypeString(), message.getCode(), message.getCodeString(),
48 // TODO -- Augmentation is not handled
49 ErrorType type = decodeErrorType(message.getType());
51 list.add(getGranularNodeErrors(message, type));
54 LOG.error("Message is not of Error Message ");
55 return Collections.emptyList();
64 protected abstract org.opendaylight.yang.gen.v1.urn.opendaylight.flow.errors.rev131116.ErrorMessage getGranularNodeErrors(ErrorMessage message, ErrorType errorType);
67 * @param type error type in source message
68 * @return enum for errorType
70 public abstract ErrorType decodeErrorType(int type);