1 package org.metricshub.ipmi.core.connection;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import org.metricshub.ipmi.core.coding.PayloadCoder;
26 import org.metricshub.ipmi.core.coding.commands.ResponseData;
27 import org.metricshub.ipmi.core.coding.commands.session.GetChannelAuthenticationCapabilities;
28 import org.metricshub.ipmi.core.coding.payload.lan.IpmiLanMessage;
29 import org.metricshub.ipmi.core.coding.protocol.Ipmiv20Message;
30
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 import java.io.IOException;
35
36
37
38
39 public class IpmiMessageHandler extends MessageHandler {
40
41 private static final Logger logger = LoggerFactory.getLogger(IpmiMessageHandler.class);
42
43 public IpmiMessageHandler(Connection connection, int timeout) throws IOException {
44 super(connection, timeout, IpmiLanMessage.MIN_SEQUENCE_NUMBER, IpmiLanMessage.MAX_SEQUENCE_NUMBER);
45 }
46
47
48
49
50
51
52
53
54 @Override
55 protected void handleIncomingMessageInternal(Ipmiv20Message message) {
56 if (message.getPayload() instanceof IpmiLanMessage) {
57 IpmiLanMessage lanMessagePayload = (IpmiLanMessage) message.getPayload();
58
59 PayloadCoder coder = messageQueue.getMessageFromQueue(lanMessagePayload.getSequenceNumber());
60 int tag = lanMessagePayload.getSequenceNumber();
61
62 logger.debug("Received message with tag " + tag);
63
64 if (coder == null) {
65 logger.debug("No message tagged with " + tag
66 + " in queue. Dropping orphan message.");
67 return;
68 }
69
70 if (coder.getClass() == GetChannelAuthenticationCapabilities.class) {
71 messageQueue.remove(tag);
72 } else {
73
74 try {
75 ResponseData responseData = coder.getResponseData(message);
76 connection.notifyResponseListeners(connection.getHandle(), tag, responseData, null);
77 } catch (Exception e) {
78 connection.notifyResponseListeners(connection.getHandle(), tag, null, e);
79 }
80 messageQueue.remove(lanMessagePayload.getSequenceNumber());
81 }
82 }
83 }
84
85 }