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.math.BigInteger;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.concurrent.CopyOnWriteArrayList;
15 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
16 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
17 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
18 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.errors.rev131116.ErrorType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotificationBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class ErrorTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
31 protected static final Logger LOG = LoggerFactory.getLogger(ErrorTranslator.class);
34 public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) {
35 if (msg instanceof ErrorMessage) {
36 ErrorMessage message = (ErrorMessage) msg;
37 List<DataObject> list = new CopyOnWriteArrayList<DataObject>();
38 LOG.error(" Error Message received: type={}[{}], code={}[{}], data={}[{}] ", message.getType(),
39 message.getTypeString(), message.getCode(), message.getCodeString(), new String(message.getData()),
40 ByteUtil.bytesToHexstring(message.getData(), " "));
42 // create a Node Error Notification event builder
43 NodeErrorNotificationBuilder nodeErrBuilder = new NodeErrorNotificationBuilder();
45 // Fill in the Node Error Notification Builder object from the Error
48 nodeErrBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(message.getXid())));
50 nodeErrBuilder.setType(ErrorType.forValue(message.getType()));
52 nodeErrBuilder.setCode(message.getCode());
54 nodeErrBuilder.setData(new String(message.getData()));
56 // TODO -- Augmentation is not handled
58 // Note Error_TypeV10 is not handled.
60 NodeErrorNotification nodeErrorEvent = nodeErrBuilder.build();
61 list.add(nodeErrorEvent);
64 LOG.error("Message is not of Error Message ");
65 return Collections.emptyList();