Search in sources :

Example 1 with StatusNotificationRequest

use of ocpp.cs._2015._10.StatusNotificationRequest in project EVSUPERVISION by EnergyTIC.

the class OperationalTestSoapOCPP16 method testBody.

private void testBody(List<MeterValue> meterValues, List<MeterValue> transactionData) {
    final int usedConnectorID = 1;
    CentralSystemService client = getForOcpp16(path);
    initStationWithBootNotification(client);
    initConnectorsWithStatusNotification(client);
    // heartbeat
    HeartbeatResponse heartbeat = client.heartbeat(new HeartbeatRequest(), REGISTERED_CHARGE_BOX_ID);
    Assertions.assertNotNull(heartbeat);
    // Auth
    AuthorizeResponse auth = client.authorize(new AuthorizeRequest().withIdTag(REGISTERED_OCPP_TAG), REGISTERED_CHARGE_BOX_ID);
    // Simple request, not much done here
    Assertions.assertNotNull(auth);
    Assertions.assertEquals(AuthorizationStatus.ACCEPTED, auth.getIdTagInfo().getStatus());
    // startTransaction
    DateTime startTimeStamp = DateTime.now();
    StartTransactionResponse start = client.startTransaction(new StartTransactionRequest().withConnectorId(usedConnectorID).withIdTag(REGISTERED_OCPP_TAG).withTimestamp(startTimeStamp).withMeterStart(0), REGISTERED_CHARGE_BOX_ID);
    Assertions.assertNotNull(start);
    int transactionID = start.getTransactionId();
    List<TransactionRecord> allTransactions = __DatabasePreparer__.getTransactionRecords();
    Assertions.assertEquals(1, allTransactions.size());
    {
        TransactionRecord t = allTransactions.get(0);
        Assertions.assertEquals(startTimeStamp, t.getStartTimestamp());
        Assertions.assertEquals(0, Integer.parseInt(t.getStartValue()));
        Assertions.assertNull(t.getStopTimestamp());
        Assertions.assertNull(t.getStopReason());
        Assertions.assertNull(t.getStopValue());
    }
    // status
    StatusNotificationResponse statusStart = client.statusNotification(new StatusNotificationRequest().withStatus(ChargePointStatus.CHARGING).withErrorCode(ChargePointErrorCode.NO_ERROR).withConnectorId(0).withTimestamp(DateTime.now()), REGISTERED_CHARGE_BOX_ID);
    Assertions.assertNotNull(statusStart);
    // send meterValues
    if (meterValues != null) {
        MeterValuesResponse meter = client.meterValues(new MeterValuesRequest().withConnectorId(usedConnectorID).withTransactionId(transactionID).withMeterValue(meterValues), REGISTERED_CHARGE_BOX_ID);
        Assertions.assertNotNull(meter);
        checkMeterValues(meterValues, transactionID);
    }
    // stopTransaction
    DateTime stopTimeStamp = DateTime.now();
    int stopValue = 30;
    StopTransactionResponse stop = client.stopTransaction(new StopTransactionRequest().withTransactionId(transactionID).withTransactionData(transactionData).withTimestamp(stopTimeStamp).withIdTag(REGISTERED_OCPP_TAG).withMeterStop(stopValue), REGISTERED_CHARGE_BOX_ID);
    {
        Assertions.assertNotNull(stop);
        List<TransactionRecord> transactionsStop = __DatabasePreparer__.getTransactionRecords();
        Assertions.assertEquals(1, transactionsStop.size());
        TransactionRecord t = transactionsStop.get(0);
        Assertions.assertEquals(stopTimeStamp, t.getStopTimestamp());
        Assertions.assertEquals(stopValue, Integer.parseInt(t.getStopValue()));
        if (transactionData != null) {
            checkMeterValues(transactionData, transactionID);
        }
    }
    // status
    StatusNotificationResponse statusStop = client.statusNotification(new StatusNotificationRequest().withStatus(ChargePointStatus.AVAILABLE).withErrorCode(ChargePointErrorCode.NO_ERROR).withConnectorId(usedConnectorID).withTimestamp(DateTime.now()), REGISTERED_CHARGE_BOX_ID);
    Assertions.assertNotNull(statusStop);
}
Also used : HeartbeatResponse(ocpp.cs._2015._10.HeartbeatResponse) MeterValuesResponse(ocpp.cs._2015._10.MeterValuesResponse) StopTransactionResponse(ocpp.cs._2015._10.StopTransactionResponse) AuthorizeRequest(ocpp.cs._2015._10.AuthorizeRequest) MeterValuesRequest(ocpp.cs._2015._10.MeterValuesRequest) CentralSystemService(ocpp.cs._2015._10.CentralSystemService) StatusNotificationResponse(ocpp.cs._2015._10.StatusNotificationResponse) ChargePoint(de.rwth.idsg.steve.repository.dto.ChargePoint) DateTime(org.joda.time.DateTime) HeartbeatRequest(ocpp.cs._2015._10.HeartbeatRequest) AuthorizeResponse(ocpp.cs._2015._10.AuthorizeResponse) StopTransactionRequest(ocpp.cs._2015._10.StopTransactionRequest) StartTransactionRequest(ocpp.cs._2015._10.StartTransactionRequest) StartTransactionResponse(ocpp.cs._2015._10.StartTransactionResponse) StatusNotificationRequest(ocpp.cs._2015._10.StatusNotificationRequest) List(java.util.List) TransactionRecord(jooq.steve.db.tables.records.TransactionRecord)

Example 2 with StatusNotificationRequest

use of ocpp.cs._2015._10.StatusNotificationRequest in project EVSUPERVISION by EnergyTIC.

the class StressTestSoapOCPP16 method attackInternal.

protected void attackInternal() throws Exception {
    final List<String> idTags = getRandomStrings(ID_TAG_COUNT);
    final List<String> chargeBoxIds = getRandomStrings(CHARGE_BOX_COUNT);
    StressTester.Runnable runnable = new StressTester.Runnable() {

        private final ThreadLocal<String> threadLocalChargeBoxId = new ThreadLocal<>();

        @Override
        public void beforeRepeat() {
            CentralSystemService client = getForOcpp16(path);
            ThreadLocalRandom localRandom = ThreadLocalRandom.current();
            threadLocalChargeBoxId.set(chargeBoxIds.get(localRandom.nextInt(chargeBoxIds.size())));
            String chargeBoxId = threadLocalChargeBoxId.get();
            // to insert threadLocalChargeBoxId into db
            BootNotificationResponse boot = client.bootNotification(new BootNotificationRequest().withChargePointVendor(getRandomString()).withChargePointModel(getRandomString()), chargeBoxId);
            Assertions.assertEquals(RegistrationStatus.ACCEPTED, boot.getStatus());
        }

        @Override
        public void toRepeat() {
            CentralSystemService client = getForOcpp16(path);
            ThreadLocalRandom localRandom = ThreadLocalRandom.current();
            String chargeBoxId = threadLocalChargeBoxId.get();
            String idTag = idTags.get(localRandom.nextInt(idTags.size()));
            int connectorId = localRandom.nextInt(1, CONNECTOR_COUNT_PER_CHARGE_BOX + 1);
            int transactionStart = localRandom.nextInt(0, Integer.MAX_VALUE);
            int transactionStop = localRandom.nextInt(transactionStart + 1, Integer.MAX_VALUE);
            HeartbeatResponse heartbeat = client.heartbeat(new HeartbeatRequest(), chargeBoxId);
            Assertions.assertNotNull(heartbeat);
            for (int i = 0; i <= CONNECTOR_COUNT_PER_CHARGE_BOX; i++) {
                StatusNotificationResponse status = client.statusNotification(new StatusNotificationRequest().withErrorCode(ChargePointErrorCode.NO_ERROR).withStatus(ChargePointStatus.AVAILABLE).withConnectorId(i).withTimestamp(DateTime.now()), chargeBoxId);
                Assertions.assertNotNull(status);
            }
            AuthorizeResponse auth = client.authorize(new AuthorizeRequest().withIdTag(idTag), chargeBoxId);
            Assertions.assertNotEquals(AuthorizationStatus.ACCEPTED, auth.getIdTagInfo().getStatus());
            StartTransactionResponse start = client.startTransaction(new StartTransactionRequest().withConnectorId(connectorId).withIdTag(idTag).withTimestamp(DateTime.now()).withMeterStart(transactionStart), chargeBoxId);
            Assertions.assertNotNull(start);
            StatusNotificationResponse statusStart = client.statusNotification(new StatusNotificationRequest().withErrorCode(ChargePointErrorCode.NO_ERROR).withStatus(ChargePointStatus.CHARGING).withConnectorId(connectorId).withTimestamp(DateTime.now()), chargeBoxId);
            Assertions.assertNotNull(statusStart);
            MeterValuesResponse meter = client.meterValues(new MeterValuesRequest().withConnectorId(connectorId).withTransactionId(start.getTransactionId()).withMeterValue(getMeterValues(transactionStart, transactionStop)), chargeBoxId);
            Assertions.assertNotNull(meter);
            StopTransactionResponse stop = client.stopTransaction(new StopTransactionRequest().withTransactionId(start.getTransactionId()).withTimestamp(DateTime.now()).withIdTag(idTag).withMeterStop(transactionStop), chargeBoxId);
            Assertions.assertNotNull(stop);
            StatusNotificationResponse statusStop = client.statusNotification(new StatusNotificationRequest().withErrorCode(ChargePointErrorCode.NO_ERROR).withStatus(ChargePointStatus.AVAILABLE).withConnectorId(connectorId).withTimestamp(DateTime.now()), chargeBoxId);
            Assertions.assertNotNull(statusStop);
        }

        @Override
        public void afterRepeat() {
        }
    };
    StressTester tester = new StressTester(THREAD_COUNT, REPEAT_COUNT_PER_THREAD);
    tester.test(runnable);
    tester.shutDown();
}
Also used : HeartbeatResponse(ocpp.cs._2015._10.HeartbeatResponse) MeterValuesResponse(ocpp.cs._2015._10.MeterValuesResponse) StopTransactionResponse(ocpp.cs._2015._10.StopTransactionResponse) AuthorizeRequest(ocpp.cs._2015._10.AuthorizeRequest) MeterValuesRequest(ocpp.cs._2015._10.MeterValuesRequest) CentralSystemService(ocpp.cs._2015._10.CentralSystemService) StatusNotificationResponse(ocpp.cs._2015._10.StatusNotificationResponse) BootNotificationRequest(ocpp.cs._2015._10.BootNotificationRequest) Helpers.getRandomString(de.rwth.idsg.steve.utils.Helpers.getRandomString) StressTester(de.rwth.idsg.steve.utils.StressTester) HeartbeatRequest(ocpp.cs._2015._10.HeartbeatRequest) BootNotificationResponse(ocpp.cs._2015._10.BootNotificationResponse) AuthorizeResponse(ocpp.cs._2015._10.AuthorizeResponse) StopTransactionRequest(ocpp.cs._2015._10.StopTransactionRequest) StartTransactionRequest(ocpp.cs._2015._10.StartTransactionRequest) StartTransactionResponse(ocpp.cs._2015._10.StartTransactionResponse) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) StatusNotificationRequest(ocpp.cs._2015._10.StatusNotificationRequest)

Example 3 with StatusNotificationRequest

use of ocpp.cs._2015._10.StatusNotificationRequest in project EVSUPERVISION by EnergyTIC.

the class CentralSystemService16_Service method statusNotification.

public StatusNotificationResponse statusNotification(StatusNotificationRequest parameters, String chargeBoxIdentity) {
    // Optional field
    DateTime timestamp = parameters.isSetTimestamp() ? parameters.getTimestamp() : DateTime.now();
    InsertConnectorStatusParams params = InsertConnectorStatusParams.builder().chargeBoxId(chargeBoxIdentity).connectorId(parameters.getConnectorId()).status(parameters.getStatus().value()).errorCode(parameters.getErrorCode().value()).timestamp(timestamp).errorInfo(parameters.getInfo()).vendorId(parameters.getVendorId()).vendorErrorCode(parameters.getVendorErrorCode()).build();
    ocppServerRepository.insertConnectorStatus(params);
    if (parameters.getStatus() == ChargePointStatus.FAULTED) {
        notificationService.ocppStationStatusFailure(chargeBoxIdentity, parameters.getConnectorId(), parameters.getErrorCode().value());
    }
    return new StatusNotificationResponse();
}
Also used : InsertConnectorStatusParams(de.rwth.idsg.steve.repository.dto.InsertConnectorStatusParams) FirmwareStatusNotificationResponse(ocpp.cs._2015._10.FirmwareStatusNotificationResponse) StatusNotificationResponse(ocpp.cs._2015._10.StatusNotificationResponse) DiagnosticsStatusNotificationResponse(ocpp.cs._2015._10.DiagnosticsStatusNotificationResponse) DateTime(org.joda.time.DateTime)

Example 4 with StatusNotificationRequest

use of ocpp.cs._2015._10.StatusNotificationRequest in project steve by RWTH-i5-IDSG.

the class OperationalTestSoapOCPP16 method testStatusNotification.

@Test
public void testStatusNotification() {
    CentralSystemService client = getForOcpp16(path);
    // -------------------------------------------------------------------------
    // init the station and verify db connector status values
    // -------------------------------------------------------------------------
    initStationWithBootNotification(client);
    // test all status enum values
    for (ChargePointStatus chargePointStatus : ChargePointStatus.values()) {
        // status for numConnectors connectors + connector 0 (main controller of CP)
        for (int i = 0; i <= numConnectors; i++) {
            StatusNotificationResponse status = client.statusNotification(new StatusNotificationRequest().withErrorCode(ChargePointErrorCode.NO_ERROR).withStatus(chargePointStatus).withConnectorId(i).withTimestamp(DateTime.now()), REGISTERED_CHARGE_BOX_ID);
            Assertions.assertNotNull(status);
        }
        List<ConnectorStatus> connectorStatusList = __DatabasePreparer__.getChargePointConnectorStatus();
        for (ConnectorStatus connectorStatus : connectorStatusList) {
            Assertions.assertEquals(chargePointStatus.value(), connectorStatus.getStatus());
            Assertions.assertEquals(ChargePointErrorCode.NO_ERROR.value(), connectorStatus.getErrorCode());
        }
    }
    // -------------------------------------------------------------------------
    // send status for faulty connector and verify db values
    // -------------------------------------------------------------------------
    int faultyConnectorId = 1;
    StatusNotificationResponse statusConnectorError = client.statusNotification(new StatusNotificationRequest().withErrorCode(ChargePointErrorCode.HIGH_TEMPERATURE).withStatus(ChargePointStatus.FAULTED).withConnectorId(faultyConnectorId).withTimestamp(DateTime.now()), REGISTERED_CHARGE_BOX_ID);
    Assertions.assertNotNull(statusConnectorError);
    List<ConnectorStatus> connectorStatusList = __DatabasePreparer__.getChargePointConnectorStatus();
    for (ConnectorStatus connectorStatus : connectorStatusList) {
        if (connectorStatus.getConnectorId() == faultyConnectorId) {
            Assertions.assertEquals(ChargePointStatus.FAULTED.value(), connectorStatus.getStatus());
            Assertions.assertEquals(ChargePointErrorCode.HIGH_TEMPERATURE.value(), connectorStatus.getErrorCode());
        } else {
            Assertions.assertNotEquals(ChargePointStatus.FAULTED.value(), connectorStatus.getStatus());
            Assertions.assertNotEquals(ChargePointErrorCode.HIGH_TEMPERATURE.value(), connectorStatus.getErrorCode());
        }
    }
}
Also used : CentralSystemService(ocpp.cs._2015._10.CentralSystemService) StatusNotificationResponse(ocpp.cs._2015._10.StatusNotificationResponse) ConnectorStatus(de.rwth.idsg.steve.repository.dto.ConnectorStatus) ChargePointStatus(ocpp.cs._2015._10.ChargePointStatus) StatusNotificationRequest(ocpp.cs._2015._10.StatusNotificationRequest) ChargePoint(de.rwth.idsg.steve.repository.dto.ChargePoint) Test(org.junit.jupiter.api.Test)

Example 5 with StatusNotificationRequest

use of ocpp.cs._2015._10.StatusNotificationRequest in project steve by RWTH-i5-IDSG.

the class OperationalTestSoapOCPP16 method initConnectorsWithStatusNotification.

private void initConnectorsWithStatusNotification(CentralSystemService client) {
    for (int i = 0; i <= numConnectors; i++) {
        StatusNotificationResponse statusBoot = client.statusNotification(new StatusNotificationRequest().withErrorCode(ChargePointErrorCode.NO_ERROR).withStatus(ChargePointStatus.AVAILABLE).withConnectorId(i).withTimestamp(DateTime.now()), REGISTERED_CHARGE_BOX_ID);
        Assertions.assertNotNull(statusBoot);
    }
}
Also used : StatusNotificationResponse(ocpp.cs._2015._10.StatusNotificationResponse) StatusNotificationRequest(ocpp.cs._2015._10.StatusNotificationRequest) ChargePoint(de.rwth.idsg.steve.repository.dto.ChargePoint)

Aggregations

StatusNotificationRequest (ocpp.cs._2015._10.StatusNotificationRequest)10 StatusNotificationResponse (ocpp.cs._2015._10.StatusNotificationResponse)10 ChargePoint (de.rwth.idsg.steve.repository.dto.ChargePoint)6 AuthorizeRequest (ocpp.cs._2015._10.AuthorizeRequest)6 CentralSystemService (ocpp.cs._2015._10.CentralSystemService)6 HeartbeatRequest (ocpp.cs._2015._10.HeartbeatRequest)6 MeterValuesRequest (ocpp.cs._2015._10.MeterValuesRequest)6 StartTransactionRequest (ocpp.cs._2015._10.StartTransactionRequest)6 StopTransactionRequest (ocpp.cs._2015._10.StopTransactionRequest)6 Helpers.getRandomString (de.rwth.idsg.steve.utils.Helpers.getRandomString)4 StressTester (de.rwth.idsg.steve.utils.StressTester)4 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)4 AuthorizeResponse (ocpp.cs._2015._10.AuthorizeResponse)4 BootNotificationRequest (ocpp.cs._2015._10.BootNotificationRequest)4 HeartbeatResponse (ocpp.cs._2015._10.HeartbeatResponse)4 MeterValuesResponse (ocpp.cs._2015._10.MeterValuesResponse)4 StartTransactionResponse (ocpp.cs._2015._10.StartTransactionResponse)4 StopTransactionResponse (ocpp.cs._2015._10.StopTransactionResponse)4 DateTime (org.joda.time.DateTime)4 ConnectorStatus (de.rwth.idsg.steve.repository.dto.ConnectorStatus)2