Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.*;

import org.apache.log4j.Logger;

Expand Down Expand Up @@ -110,9 +109,9 @@ public IpmiAsyncConnector(int port, InetAddress address) throws IOException {
loadProperties();
}

private void loadProperties() throws IOException {
private void loadProperties() throws IOException {
retries = Integer.parseInt(PropertiesManager.getInstance().getProperty("retries"));
}
}

/**
* Creates connection to the remote host.
Expand Down Expand Up @@ -153,35 +152,25 @@ public List<CipherSuite> getAvailableCipherSuites(
++tries;
result = connectionManager
.getAvailableCipherSuites(connectionHandle.getHandle());
} catch (IPMIException e) {
logger.warn("Failed to receive answer, cause:", e);
if (tries > retries) {
throw e;
}
} catch (StateConnectionException e) {
// state error, no retry
throw e;
} catch (Exception e) {
if(e instanceof IOException) {
// Normal network error
logger.warn("Failed to receive answer, cause: " + e.getMessage());
} else {
logger.warn("Failed to receive answer, cause:", e);
}
logger.warn("Failed to receive answer, cause:", e);
if (tries > retries) {
throw e;
logger.warn("Failed to receive answer, cause: "
+ e.getMessage());

return Arrays.asList(CipherSuite.getEmpty());
}
}
}
return result;
}

public List<CipherSuite> getAllCipherSuites(
ConnectionHandle connectionHandle) throws StateConnectionException {
List<CipherSuite> result = connectionManager
.getAllCipherSuites(connectionHandle.getHandle());
return result;
}
ConnectionHandle connectionHandle) throws StateConnectionException {
List<CipherSuite> result = connectionManager
.getAllCipherSuites(connectionHandle.getHandle());
return result;
}

/**
* Gets the authentication capabilities for the connection with the remote
Expand Down Expand Up @@ -214,15 +203,15 @@ public GetChannelAuthenticationCapabilitiesResponseData getChannelAuthentication
requestedPrivilegeLevel);
connectionHandle.setCipherSuite(cipherSuite);
connectionHandle.setPrivilegeLevel(requestedPrivilegeLevel);
} catch (StateConnectionException e) {
// state error, no retry
} catch (StateConnectionException e) {
// state error, no retry
throw e;
} catch (Exception e) {
if(e instanceof IOException) {
if (e instanceof IOException) {
// Normal network error
logger.warn("Failed to receive answer, cause:" + e.getMessage());
} else {
logger.warn("Failed to receive answer, cause:", e);
logger.warn("Failed to receive answer, cause:", e);
}
logger.warn("Failed to receive answer, cause:", e);
if (tries > retries) {
Expand Down Expand Up @@ -264,15 +253,15 @@ public void openSession(ConnectionHandle connectionHandle, String username,
connectionHandle.getPrivilegeLevel(), username,
password, bmcKey);
succeded = true;
} catch (StateConnectionException e) {
// state error, no retry
} catch (StateConnectionException e) {
// state error, no retry
throw e;
} catch (Exception e) {
if(e instanceof IOException) {
if (e instanceof IOException) {
// Normal network error
logger.warn("Failed to receive answer, cause:" + e.getMessage());
} else {
logger.warn("Failed to receive answer, cause:", e);
logger.warn("Failed to receive answer, cause:", e);
}
if (tries > retries) {
throw e;
Expand Down Expand Up @@ -308,15 +297,15 @@ public void closeSession(ConnectionHandle connectionHandle)
connectionManager.getConnection(connectionHandle.getHandle())
.closeSession();
succeded = true;
} catch (StateConnectionException e) {
// state error, no retry
} catch (StateConnectionException e) {
// state error, no retry
throw e;
} catch (Exception e) {
if(e instanceof IOException) {
if (e instanceof IOException) {
// Normal network error
logger.warn("Failed to receive answer, cause:" + e.getMessage());
} else {
logger.warn("Failed to receive answer, cause:", e);
logger.warn("Failed to receive answer, cause:", e);
}
if (tries > retries) {
throw e;
Expand Down Expand Up @@ -362,15 +351,15 @@ public int sendMessage(ConnectionHandle connectionHandle,
}
logger.debug("Sending message with tag " + tag + ", try "
+ tries);
} catch (StateConnectionException e) {
// state error, no retry
} catch (StateConnectionException e) {
// state error, no retry
throw e;
} catch (Exception e) {
if(e instanceof IOException) {
if (e instanceof IOException) {
// Normal network error
logger.warn("Failed to receive answer, cause:" + e.getMessage());
} else {
logger.warn("Failed to receive answer, cause:", e);
logger.warn("Failed to receive answer, cause:", e);
}
if (tries > retries) {
throw e;
Expand Down Expand Up @@ -444,15 +433,15 @@ public void closeConnection(ConnectionHandle handle) {
public void tearDown() {
connectionManager.close();
}
/**
* Changes the timeout value for connection with the given handle.
* @param handle
* - {@link ConnectionHandle} associated with the remote host.
* @param timeout
* - new timeout value in ms
*/
public void setTimeout(ConnectionHandle handle, int timeout) {
connectionManager.getConnection(handle.getHandle()).setTimeout(timeout);
}

/**
* Changes the timeout value for connection with the given handle.
* @param handle
* - {@link ConnectionHandle} associated with the remote host.
* @param timeout
* - new timeout value in ms
*/
public void setTimeout(ConnectionHandle handle, int timeout) {
connectionManager.getConnection(handle.getHandle()).setTimeout(timeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class GetSensorReading extends IpmiCommandCoder {

private byte sensorId;
private final byte sensorId;

/**
* Initiates class for both encoding and decoding.
Expand Down Expand Up @@ -67,7 +67,7 @@ public NetworkFunction getNetworkFunction() {
@Override
protected IpmiPayload preparePayload(int sequenceNumber)
throws NoSuchAlgorithmException, InvalidKeyException {
byte[] payloadData = new byte[] { sensorId };
byte[] payloadData = new byte[]{sensorId};
return new IpmiLanRequest(getNetworkFunction(), getCommandCode(),
payloadData, TypeConverter.intToByte(sequenceNumber % 64));
}
Expand All @@ -92,36 +92,32 @@ public ResponseData getResponseData(IpmiMessage message)

byte[] raw = message.getPayload().getIpmiCommandData();

if (raw.length < 3) {
throw new IllegalArgumentException("Invalid response length");
}

GetSensorReadingResponseData responseData = new GetSensorReadingResponseData();

responseData.setSensorReading(raw[0]);

responseData
.setSensorStateValid((TypeConverter.byteToInt(raw[1]) & 0x20) == 0);

responseData.setSensorState(SensorState.parseInt((TypeConverter
.byteToInt(raw[2])) & 0x3f));
if (raw.length > 2)
responseData.setSensorState(SensorState.parseInt((TypeConverter
.byteToInt(raw[2])) & 0x3f));

boolean[] states = null;

if (raw.length > 3) {
if (raw.length > 3)
states = new boolean[16];
} else {
else
states = new boolean[8];
}

for (int i = 0; i < 8; ++i) {
states[i] = (TypeConverter.byteToInt(raw[2]) & (0x1 << i)) != 0;
}
if (raw.length > 2)
for (int i = 0; i < 8; ++i)
states[i] = (TypeConverter.byteToInt(raw[2]) & (0x1 << i)) != 0;

if (raw.length > 3) {
for (int i = 0; i < 7; ++i) {
for (int i = 0; i < 7; ++i)
states[i + 8] = (TypeConverter.byteToInt(raw[3]) & (0x1 << i)) != 0;
}

states[15] = false;
}

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/veraxsystems/vxipmi/connection/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public class Connection extends TimerTask implements MachineObserver {
* - when properties file was not found
*/
public Connection(Messenger messenger, int handle) throws FileNotFoundException, IOException {
stateMachine = new StateMachine(messenger);
this.handle = handle;
stateMachine = new StateMachine(messenger);
this.handle = handle;
timeout = Integer.parseInt(PropertiesManager.getInstance().getProperty("timeout"));
}
}

public int getHandle() {
return handle;
Expand Down Expand Up @@ -260,11 +260,11 @@ public List<CipherSuite> getAllCipherSuites(int tag) throws StateConnectionExcep
}
stateMachine.doTransition(new GetChannelCipherSuitesPending(tag));
stateMachine.doTransition(new DefaultAck());
CipherSuite[] allCs = new CipherSuite[] {
new CipherSuite((byte) 0,(byte) 0,(byte) 0,(byte) 0),
new CipherSuite((byte) 1,(byte) 1,(byte) 0,(byte) 0),
new CipherSuite((byte) 2,(byte) 1,(byte) 1,(byte) 0),
new CipherSuite((byte) 3,(byte) 1,(byte) 1,(byte) 1),
CipherSuite[] allCs = new CipherSuite[]{
new CipherSuite((byte) 0, (byte) 0, (byte) 0, (byte) 0),
new CipherSuite((byte) 1, (byte) 1, (byte) 0, (byte) 0),
new CipherSuite((byte) 2, (byte) 1, (byte) 1, (byte) 0),
new CipherSuite((byte) 3, (byte) 1, (byte) 1, (byte) 1),
new CipherSuite((byte) 4,(byte) 1,(byte) 1,(byte) 2),
};
return Arrays.asList(allCs);
Expand Down Expand Up @@ -318,7 +318,7 @@ public GetChannelAuthenticationCapabilitiesResponseData getChannelAuthentication
PrivilegeLevel requestedPrivilegeLevel) throws Exception {

if (!(stateMachine.getCurrent().getClass() == Ciphers.class)) {
throw new StateConnectionException(stateMachine.getCurrent());
stateMachine.setCurrent(new Ciphers());
}

lastAction = null;
Expand Down Expand Up @@ -602,10 +602,10 @@ public void notify(StateMachineAction action) {
sik = ((GetSikAction) action).getSik();
} else if (!(action instanceof MessageAction)) {
lastAction = action;
if (action instanceof ErrorAction) {
ErrorAction errorAction = (ErrorAction) action;
if (action instanceof ErrorAction) {
ErrorAction errorAction = (ErrorAction) action;
logger.error(errorAction.getException().getMessage(), errorAction.getException());
}
}
} else {
handleIncomingMessage(((MessageAction) action).getIpmiv20Message());
}
Expand Down