|
@@ -5,17 +5,25 @@ import com.beanit.asn1bean.ber.types.*;
|
|
|
import com.beanit.asn1bean.ber.types.string.BerUTF8String;
|
|
|
import com.beanit.asn1dsrc.dsrc.*;
|
|
|
import com.beanit.asn1dsrc.enums.eAuthInfo;
|
|
|
+import com.beanit.asn1dsrc.enums.eObjectId;
|
|
|
import com.beanit.asn1dsrc.util.DsrcAsn1Utils;
|
|
|
import com.its.app.utils.ByteUtils;
|
|
|
import com.its.app.utils.SysUtils;
|
|
|
import com.its.dsrc.DsrcCommServerApplication;
|
|
|
import com.its.dsrc.entity.TbRseCtlr;
|
|
|
import com.its.dsrc.global.AppRepository;
|
|
|
+import com.its.dsrc.xnettcp.dsrc.handler.DsrcAsn1ServerIdleStatePacketHandler;
|
|
|
+import com.its.dsrc.xnettcp.dsrc.process.response.*;
|
|
|
+import com.its.dsrc.xnettcp.dsrc.process.service.SubscriptionService;
|
|
|
+import com.its.dsrc.xnettcp.dsrc.process.service.impl.SubscriptionRegisterService;
|
|
|
+import com.its.dsrc.xnettcp.dsrc.process.service.impl.SubscriptionSingleService;
|
|
|
+import io.netty.channel.ChannelHandlerContext;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.List;
|
|
@@ -418,4 +426,175 @@ public class DsrcCommServerApplicationTests {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testIntToByteArray() {
|
|
|
+ int[] intArr = {48, -127, -89, -128, 1, 1, -127, -127, -99, 48, -127, -102, -128, 1, 1, -127, 1, 8, -126, 1, 10, -93, 0, -92, -127, -116, -91, -127, -119, -128, 1, 1, -95, -127, -125, -96, -127, -128, -128, 1, 0, -127, 1, 0, -94, 41, -94, 39, -96, 37, -128, 1, 60, -95, 32, -128, 2, 7, -25, -127, 1, 2, -126, 1, 9, -125, 1, 10, -124, 1, 59, -123, 1, 56, -90, 3, -126, 1, 0, -89, 6, -128, 1, 9, -127, 1, 0, -125, 1, 3, -124, 1, 10, -123, 1, -1, -90, 68, -128, 6, 40, -5, 40, 5, 0, 1, -95, 58, 48, 56, 48, 54, -128, 1, 111, -127, 5, 102, 85, 51, 95, 98, -94, 21, 12, 1, 65, 12, 1, 53, 12, 1, 109, 12, 1, 79, 12, 1, 107, 12, 1, 77, 12, 1};
|
|
|
+
|
|
|
+ for (int aa : intArr) {
|
|
|
+ log.info("{}", String.format("%02X", (byte)aa));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testPacketRecvData() {
|
|
|
+ String data = "3081A780010181819D30819A80010181010882010AA300A4818CA58189800101A18183A08180800100810100A229A227A02580013CA120800207E781010282010983010A84013B850138A603820100A70680010981010083010384010A8501FFA644800628FB28050001A13A3038303680016F81056655335F62A2150C01410C01350C016D0C014F0C016B0C014D0C01";
|
|
|
+ byte[] inBytes = ByteUtils.hexToByteArray(data);
|
|
|
+ log.error("Packet Length: {}", inBytes.length);
|
|
|
+ DatexDataPacket datexDataPacket = new DatexDataPacket();
|
|
|
+ try {
|
|
|
+ int pktLength = datexDataPacket.decode(new ByteArrayInputStream(inBytes, 0, inBytes.length));
|
|
|
+ }
|
|
|
+ catch(IOException e) {
|
|
|
+ }
|
|
|
+ log.error("{}", datexDataPacket);
|
|
|
+ BerOctetString berOctetString = datexDataPacket.getDatexData();
|
|
|
+ C2CAuthenticatedMessage c2c = new C2CAuthenticatedMessage();
|
|
|
+ try {
|
|
|
+ int authLength = c2c.decode(new ByteArrayInputStream(berOctetString.value, 0, berOctetString.value.length));
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ log.error("{}", c2c);
|
|
|
+
|
|
|
+ String ipAddress = "127.0.0.1";
|
|
|
+ PDUs pdus = c2c.getPdu();
|
|
|
+ eAuthInfo cmd = eAuthInfo.getByValue(c2c.getDatexAuthenticationInfoText().value[0]);
|
|
|
+
|
|
|
+ log.info("TcpServerDataProcess.process: {}", cmd.toString());
|
|
|
+
|
|
|
+ ChannelHandlerContext ctx = null;
|
|
|
+ TbRseCtlr obj = null;;
|
|
|
+
|
|
|
+ DsrcAsn1Response response = null;
|
|
|
+ switch (cmd) {
|
|
|
+ case AI_Initiate : //(0x01, "AI_Initiate"), /* 초기 통신연결을 위한 개시 요청 데이터 패킷 */
|
|
|
+ // 서버모드 처리내용 없음(평택 서버인데 클라이언트가 서버로 동작 => 로그인 요청해야함)
|
|
|
+ if (pdus.getDatexInitiateNull() != null) {
|
|
|
+ response = new InitiateResponse(obj, ctx, c2c);
|
|
|
+ }
|
|
|
+ else if (pdus.getSubscription() != null) {
|
|
|
+ response = new SubscriptionResponse(obj, ctx, c2c);
|
|
|
+ }
|
|
|
+ else if (pdus.getPublication() != null) {
|
|
|
+ response = new PublicationResponse(obj, ctx, c2c);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case AI_Login : //(0x02, "AI_Login"), /* 서버에 접속하기 위한 클라이언트의 로그인 데이터 패킷 */
|
|
|
+ response = new LoginResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ case AI_FrED : //(0x03, "AI_FrED"), /* 서버와 클라이언트의 연결을 유지하기 위한 확인 데이터 패킷 */
|
|
|
+ response = new FredResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ case AI_Terminate : //(0x04, "AI_Terminate"), /* 연결을 종료하고자 할 때, 서버에서 클라이언트에 요청하는 데이터 패킷 */
|
|
|
+ response = new TerminateResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ case AI_Logout : //(0x05, "AI_Logout"), /* 접속을 종료하기 위한 클라이언트의 로그아웃 데이터 패킷 */
|
|
|
+ response = new LogoutResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ case AI_Subscription: //(0x06, "AI_Subscription"), /* 클라이언트가 서버에 정보를 요청할 경우 송신하는 데이터 패킷 */
|
|
|
+ response = new SubscriptionResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ case AI_Publication : //(0x07, "AI_Publication"), /* 클라이언트가 요청한 정보를 제공하기 위한 데이터 패킷 - 요청에 대한 정보공개*/
|
|
|
+ response = new PublicationResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ case AI_Accept : //(0x09, "AI_Accept"), /* 클라이언트의 요청에 대한 수용 */
|
|
|
+ response = new AcceptResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ case AI_Reject : //(0x0A, "AI_Reject"); /* 클라이언트의 요청에 대한 거부 */
|
|
|
+ // 운영단말 명령에 대한 거부도 발생할 수 있으므로 운영단말로 결과를 전송한다.
|
|
|
+ response = new RejectResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ case AI_TransferDone: //(0x08, "AI_TransferDone"), /* 클라이언트가 요청한 정보를 파일형태로 제공하기 위한 데이터 패킷 */
|
|
|
+ // 처리내용 없음
|
|
|
+ response = new TransferDoneResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ case AI_Null : //(0x00, "AI_Null"), /* NULL */
|
|
|
+ // 처리내용 없음
|
|
|
+ response = new NullResponse(obj, ctx, c2c);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ log.warn("{}. process: Unknown packet: {}, {}", "ipAddress", cmd.toString(), obj.toString());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (response != null) {
|
|
|
+ int objectId = 0;
|
|
|
+ SubscriptionService subscriptionService = null;
|
|
|
+ C2CAuthenticatedMessage resC2c = null;
|
|
|
+ //PDUs pdus = c2c.getPdu();
|
|
|
+ Subscription subscription = pdus.getSubscription();
|
|
|
+ if (subscription != null) {
|
|
|
+ int subscribeSerialNbr = subscription.getDatexSubscribeSerialNbr().intValue();
|
|
|
+ SubscriptionType subscriptionType = subscription.getDatexSubscribeType();
|
|
|
+ BerEnum cancelReasonCd = subscriptionType.getDatexSubscribeCancelReasonCd();
|
|
|
+ if (subscriptionType != null) {
|
|
|
+ SubscriptionData subscriptionData = subscriptionType.getSubscription();
|
|
|
+ if (subscriptionData != null) {
|
|
|
+ boolean persistentBool = subscriptionData.getDatexSubscribePersistentBool().value;
|
|
|
+ int statusCd = subscriptionData.getDatexSubscribeStatusCd().value.intValue(); // new, update
|
|
|
+ int publishFormatCd = subscriptionData.getDatexSubscribePublishFormatCd().value.intValue();
|
|
|
+ int priorityNbr = subscriptionData.getDatexSubscriptionPriorityNbr().value.intValue();
|
|
|
+ boolean guaranteeBool = subscriptionData.getDatexSubscribeGuaranteeBool().value;
|
|
|
+
|
|
|
+ objectId = DsrcAsn1Utils.getObjectId(subscriptionData.getDatexSubscribePdu().getEndApplicationMessageId().value);
|
|
|
+ //log.info("SubscriptionResponse.response: objectId: {}", objectId);
|
|
|
+
|
|
|
+ if (objectId != eObjectId.OBJ_ProbeVehicleDetectionRoadSide.getValue() &&
|
|
|
+ objectId > eObjectId.OBJ_DSRCRecentOBUTransactionInfo.getValue()) {
|
|
|
+ // Reject
|
|
|
+// resC2c = DsrcAsn1Reject.makeC2CAuthenticatedMessage(obj, ctx.channel(), c2c,
|
|
|
+// eRejectSubscription.Reject_Subscription_cd_invalidSubscriptionMsgId.getValue());
|
|
|
+ log.info("SubscriptionResponse.response: {}, Reject, objectId: {}", ipAddress, objectId);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ SubscriptionMode subscriptionMode = subscriptionData.getDatexSubscribeMode();
|
|
|
+ if (subscriptionMode != null) {
|
|
|
+ // subscriptionMode = single, event-driven, periodic
|
|
|
+ if (subscriptionMode.getSingle() != null) {
|
|
|
+ //log.info("SubscriptionResponse.response: {}, SubscriptionSingleService", ipAddress);
|
|
|
+ subscriptionService = SubscriptionSingleService.getInstance();
|
|
|
+ } else if (subscriptionMode.getEventDriven() != null) {
|
|
|
+ //log.info("SubscriptionResponse.response: {}, SubscriptionRegisterService[EventDriven]", ipAddress);
|
|
|
+ subscriptionService = SubscriptionRegisterService.getInstance();
|
|
|
+ } else if (subscriptionMode.getPeriodic() != null) {
|
|
|
+ //log.info("SubscriptionResponse.response: {}, SubscriptionRegisterService[Periodic]", ipAddress);
|
|
|
+ subscriptionService = SubscriptionRegisterService.getInstance();
|
|
|
+ ByteArrayInputStream berInputStream = new ByteArrayInputStream(subscriptionData.getDatexSubscribePdu().getEndApplicationMessageMsg().value);
|
|
|
+ MultiMediaDataList dataOrg = new MultiMediaDataList();
|
|
|
+ try {
|
|
|
+ dataOrg.decode(berInputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ //throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ List<MultiMediaData> dataLists = dataOrg.getMultiMediaData();
|
|
|
+ for (MultiMediaData media : dataLists) {
|
|
|
+ log.info("{}", media);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (guaranteeBool) {
|
|
|
+ //resC2c = DsrcAsn1Accept.makeC2CAuthenticatedMessage(this.obj, this.ctx.channel(), this.c2c);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.warn("SubscriptionResponse.response: {}, SubscriptionMode null", ipAddress);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (cancelReasonCd != null) {
|
|
|
+ // Cancel
|
|
|
+ int cancelReasonId = cancelReasonCd.value.intValue();
|
|
|
+ //resC2c = DsrcAsn1Accept.makeC2CAuthenticatedMessage(this.obj, this.ctx.channel(), this.c2c);
|
|
|
+ log.info("SubscriptionResponse.response: {}, Accept, cancelReasonCd: {}", ipAddress, cancelReasonId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (subscriptionService != null) {
|
|
|
+ //subscriptionService.response(this.obj, this.ctx.channel(), objectId, subscription);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ log.error("TcpServerDataProcess.process: {}, unknown packet. will be closed.", ipAddress);
|
|
|
+ DsrcAsn1ServerIdleStatePacketHandler.disconnectChannel(obj, ctx.channel());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|