1 package org.opendaylight.openflowplugin.openflow.md.core.translator;
3 import java.math.BigInteger;
5 import java.util.concurrent.CopyOnWriteArrayList;
7 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
8 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
9 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
10 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.errors.rev131116.ErrorType;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotificationBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class ErrorTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
23 protected static final Logger LOG = LoggerFactory.getLogger(ErrorTranslator.class);
26 public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) {
27 if (msg instanceof ErrorMessage) {
28 ErrorMessage message = (ErrorMessage) msg;
29 List<DataObject> list = new CopyOnWriteArrayList<DataObject>();
30 LOG.error(" Error Message received: type={}[{}], code={}[{}], data={}[{}] ", message.getType(),
31 message.getTypeString(), message.getCode(), message.getCodeString(), new String(message.getData()),
32 ByteUtil.bytesToHexstring(message.getData(), " "));
34 // create a Node Error Notification event builder
35 NodeErrorNotificationBuilder nodeErrBuilder = new NodeErrorNotificationBuilder();
37 // Fill in the Node Error Notification Builder object from the Error
40 nodeErrBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(message.getXid())));
42 nodeErrBuilder.setType(ErrorType.forValue(message.getType()));
44 nodeErrBuilder.setCode(message.getCode());
46 nodeErrBuilder.setData(new String(message.getData()));
48 // TODO -- Augmentation is not handled
50 // Note Error_TypeV10 is not handled.
52 NodeErrorNotification nodeErrorEvent = nodeErrBuilder.build();
53 list.add(nodeErrorEvent);
56 LOG.error("Message is not of Error Message ");