Commit 9ac790aa authored by juvancic's avatar juvancic
Browse files

updated ta module

parent 618103eb
Loading
Loading
Loading
Loading
+254 −251
Original line number Original line Diff line number Diff line
@@ -32,18 +32,20 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
	TriPortId comPortId = null;
	TriPortId comPortId = null;
	TriPortId tsiPortId = null;
	TriPortId tsiPortId = null;


	Logger log = null;
	protected Logger log = null;


	public static Hashtable<String, TriPortId> ComponentCollection = new Hashtable<String,TriPortId>();
	public static Hashtable<String, TriPortId> ComponentCollection = new Hashtable<String,TriPortId>();
	public static Hashtable<String, TriPortId> ComponentCollectionCompPort = new Hashtable<String,TriPortId>();
	public static Hashtable<String, TriPortId> ComponentCollectionCompPort = new Hashtable<String,TriPortId>();
	public static Hashtable<String, FilterPackets> ComponentCollectionFilter2Port = new Hashtable<String,FilterPackets>();
	public static Hashtable<String, FilterPackets> ComponentCollectionFilter2Port = new Hashtable<String,FilterPackets>();
	
	
	private Queue<TriComponentId> FilterMsgFIFO = new LinkedList<>(); // for selection sequence to which PTC first send
	private Queue<TriComponentId> FilterMsgFIFO = new LinkedList<>(); //for selection sequence to which PTC first send resonse
																		// resonse


	public String tracefile="";
	public String tracefile="";
    
    
	public class FilterPackets {
	
	
    public class FilterPackets
    {
        public List packets;
        public List packets;
        public String filter;
        public String filter;
        public TriComponentId componentId;
        public TriComponentId componentId;
@@ -51,25 +53,31 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
        public TriCommunicationTE cte;
        public TriCommunicationTE cte;
        final IotConnectionOffline this$0;
        final IotConnectionOffline this$0;


		public boolean equals(Object obj) {
        public boolean equals(Object obj)
			if (obj instanceof FilterPackets) {
        {
            if(obj instanceof FilterPackets)
            {
                return filter.equals(((FilterPackets)obj).filter);
                return filter.equals(((FilterPackets)obj).filter);
			} else {
            } else
            {
                return false;
                return false;
            }
            }
        }
        }


		public int hashCode() {
        public int hashCode()
        {
            return filter.hashCode()+componentId.hashCode();
            return filter.hashCode()+componentId.hashCode();
        }
        }


		public FilterPackets(String filter) {
        public FilterPackets(String filter)
        {
            super();
            super();
            this$0 = IotConnectionOffline.this;
            this$0 = IotConnectionOffline.this;
            this.filter = filter;
            this.filter = filter;
        }
        }


		public FilterPackets(String filter, TriComponentId componentId, TriPortId tsiPortId, TriCommunicationTE cte) {
        public FilterPackets(String filter,  TriComponentId componentId, TriPortId tsiPortId, TriCommunicationTE cte)
        {
            this(filter);
            this(filter);
            this.componentId = componentId;
            this.componentId = componentId;
            this.tsiPortId = tsiPortId;
            this.tsiPortId = tsiPortId;
@@ -81,22 +89,21 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
        }
        }
        
        
        public String toString(){
        public String toString(){
			return (componentId.getComponentName() + " " + tsiPortId.toString() + " "
        	return (componentId.getComponentName() + " " + tsiPortId.toString() + " " + ((filter != null) ? filter : "(null)"));// + "\n" + "packets count: " + ((packets != null) ? packets.size() : "(null)"));
					+ ((filter != null) ? filter : "(null)"));// + "\n" + "packets count: " + ((packets != null) ?
																// packets.size() : "(null)"));
        }
        }
    }
    }
	
	
	
	public IotConnectionOffline(Logger log, TriCommunicationTE cte) {
	public IotConnectionOffline(Logger log, TriCommunicationTE cte) {
		this.cte = cte;
		this.cte = cte;
		this.log = log;
		this.log = log;
	}
	}


	
	public synchronized TriStatus triMap(TriPortId comPortId, TriPortId tsiPortId) {
	public synchronized TriStatus triMap(TriPortId comPortId, TriPortId tsiPortId) {
		try {
		try {
			boolean result=false;
			boolean result=false;
			log.debug("comPortId.getPortName()= " + comPortId.getPortName() + "; tsiPortId.getPortName()= "
			log.debug("comPortId.getPortName()= " + comPortId.getPortName() + "; tsiPortId.getPortName()= " + tsiPortId.getPortName());
					+ tsiPortId.getPortName());
			// Save parameters for later usage
			// Save parameters for later usage
			//this.comPortId = comPortId;
			//this.comPortId = comPortId;
			//this.tsiPortId = tsiPortId;
			//this.tsiPortId = tsiPortId;
@@ -116,27 +123,31 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
				   //log.debug(""+ComponentCollection.elements().toString());
				   //log.debug(""+ComponentCollection.elements().toString());
				   result = true; //assume MTC acport was succesfully conected
				   result = true; //assume MTC acport was succesfully conected
				}
				}
			} else if (tsiPortId.getPortName().equals("sipPort")) {
			}else
			    if (tsiPortId.getPortName().equals("sipPort")){
			    	ComponentCollection.put(comPortId.getComponent().getComponentName()+"-data", tsiPortId);
			    	ComponentCollection.put(comPortId.getComponent().getComponentName()+"-data", tsiPortId);
			    	ComponentCollectionCompPort.put(comPortId.getComponent().getComponentName()/*+"-sip"*/, comPortId);
			    	ComponentCollectionCompPort.put(comPortId.getComponent().getComponentName()/*+"-sip"*/, comPortId);
					//log.debug(""+ComponentCollection.elements().toString());
					//log.debug(""+ComponentCollection.elements().toString());
					result = true; //asuume MTC acport was succesfully conected
					result = true; //asuume MTC acport was succesfully conected
			} else if (tsiPortId.getPortName().equals("diameterPort")) {
			}else
			    if (tsiPortId.getPortName().equals("diameterPort")){
			    	ComponentCollection.put(comPortId.getComponent().getComponentName()+"-data", tsiPortId);
			    	ComponentCollection.put(comPortId.getComponent().getComponentName()+"-data", tsiPortId);
				ComponentCollectionCompPort.put(comPortId.getComponent().getComponentName()/* +"-diameter" */,
			    	ComponentCollectionCompPort.put(comPortId.getComponent().getComponentName()/*+"-diameter"*/, comPortId);
						comPortId);
					//log.debug(""+ComponentCollection.elements().toString());
					//log.debug(""+ComponentCollection.elements().toString());
					result = true; //asuume MTC acport was succesfully conected
					result = true; //asuume MTC acport was succesfully conected
			} else if (tsiPortId.getPortName().equals("dPort")) {
			}else
			    if (tsiPortId.getPortName().equals("dPort")){
			    	ComponentCollection.put(comPortId.getComponent().getComponentName()+"-d", tsiPortId);
			    	ComponentCollection.put(comPortId.getComponent().getComponentName()+"-d", tsiPortId);
			    	ComponentCollectionCompPort.put(comPortId.getComponent().getComponentName()+"-d", comPortId);
			    	ComponentCollectionCompPort.put(comPortId.getComponent().getComponentName()+"-d", comPortId);
					//log.debug(""+ComponentCollection.elements().toString());
					//log.debug(""+ComponentCollection.elements().toString());
					result = true; //asuume MTC acport was succesfully conected
					result = true; //asuume MTC acport was succesfully conected
			} else if (tsiPortId.getPortName().equals("")) {
			}else
				if(tsiPortId.getPortName().equals("")){
					result = false;
					result = false;
			}
			}


			return (result == true) ? new TriStatusImpl(TriStatus.TRI_OK) : new TriStatusImpl(TriStatus.TRI_ERROR);
			return (result == true) ? new TriStatusImpl(TriStatus.TRI_OK)
					: new TriStatusImpl(TriStatus.TRI_ERROR);
			//return new TriStatusImpl(TriStatus.TRI_OK);
			//return new TriStatusImpl(TriStatus.TRI_OK);
		} catch (Throwable ex) {
		} catch (Throwable ex) {
			ex.printStackTrace();
			ex.printStackTrace();
@@ -145,8 +156,7 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
	}
	}


    //public synchronized TriStatus triSend(TriAddress triAddress,
    //public synchronized TriStatus triSend(TriAddress triAddress,
	public TriStatus triSend(TriComponentId componentId, TriPortId tsiPortId, TriAddress triAddress,
    public TriStatus triSend(TriComponentId componentId, TriPortId tsiPortId,TriAddress triAddress,	TriMessage triMessage) {
			TriMessage triMessage) {


    	try {
    	try {
			byte[] buffer = triMessage.getEncodedMessage();
			byte[] buffer = triMessage.getEncodedMessage();
@@ -158,14 +168,12 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
			
			
			int recv_reply = 0;
			int recv_reply = 0;
			int iotmsgType = buffer[0]&0xFF | buffer[1]&0xFF << 8; 
			int iotmsgType = buffer[0]&0xFF | buffer[1]&0xFF << 8; 
			int iotmsgLen = 2 + 4 + (((buffer[2] & 0xFF)) | ((buffer[3] & 0xFF) << 8) | ((buffer[4] & 0xFF) << 16)
	    	int iotmsgLen  = 2+4+(((buffer[2] & 0xFF))|((buffer[3] & 0xFF) << 8)|((buffer[4] & 0xFF) << 16) |  ((buffer[5] & 0xFF)<<24));
					| ((buffer[5] & 0xFF) << 24));
	       
	       
	    	switch (iotmsgType){
	    	switch (iotmsgType){
	        case 7: /*OPEN_DEVICE_REQ	  =	  0x0007; /**< ID of OpenDeviceRequest */
	        case 7: /*OPEN_DEVICE_REQ	  =	  0x0007; /**< ID of OpenDeviceRequest */
	        	log.info("ConfigureREQ");
	        	log.info("ConfigureREQ");
				byte[] confresp = { 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
	        	byte[] confresp= {0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};/*OPEN_DEVICE_REP	  =	  0x0008; /**< ID of OpenDeviceReply*/
						0x00 };/* OPEN_DEVICE_REP = 0x0008; /**< ID of OpenDeviceReply */
	        	
	        	
	        	log.debug(this.getTraceFile());
	        	log.debug(this.getTraceFile());
	        	
	        	
@@ -174,14 +182,12 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt


	        case 2: /*SET_FILTER_REQ       =   0x0002; /**< ID of SetFilterRequest */
	        case 2: /*SET_FILTER_REQ       =   0x0002; /**< ID of SetFilterRequest */
	        	log.info("FilterREQ: " + componentId.getComponentName());
	        	log.info("FilterREQ: " + componentId.getComponentName());
				byte[] filterresp = { 0x09, 0x00, 0x01, 0x00, 0x00, 0x00,
	        	byte[] filterresp= {0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};/*SET_FILTER_REP    =   0x0009; /**< ID of SetFilterReply */
						0x00 };/* SET_FILTER_REP = 0x0009; /**< ID of SetFilterReply */
	        		        	
	        		        	
	        	String filter = new String(buffer,10,buffer.length-10);
	        	String filter = new String(buffer,10,buffer.length-10);
	        	log.debug("FilterREQ: filter=" + filter);
	        	log.debug("FilterREQ: filter=" + filter);
	        	try {
	        	try {
					FilterPackets fp = new FilterPackets(filter, componentId,
	        	    FilterPackets fp = new FilterPackets(filter, componentId,ComponentCollection.get(componentId.getComponentName()+"-data"), this.cte/*tsiPortId*/);
							ComponentCollection.get(componentId.getComponentName() + "-data"), this.cte/* tsiPortId */);
	        	    ComponentCollectionFilter2Port.put(componentId.getComponentName(), fp);
	        	    ComponentCollectionFilter2Port.put(componentId.getComponentName(), fp);
				} catch (Exception e) {
				} catch (Exception e) {
					// TODO Auto-generated catch block
					// TODO Auto-generated catch block
@@ -195,8 +201,7 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
	        case 3:/*START_CAPTURE_REQ    =   0x0003; /**< ID of StartCaptureRequest */
	        case 3:/*START_CAPTURE_REQ    =   0x0003; /**< ID of StartCaptureRequest */
	        	log.info("StartCaptureREQ: " + componentId.getComponentName());
	        	log.info("StartCaptureREQ: " + componentId.getComponentName());
	        	log.info("StartCaptureREQ: ComponentCollectionFilter2Port=" + ComponentCollectionFilter2Port.size());
	        	log.info("StartCaptureREQ: ComponentCollectionFilter2Port=" + ComponentCollectionFilter2Port.size());
				byte[] startcapresp = { 0x04, 0x00, 0x01, 0x00, 0x00, 0x00,
	        	byte[] startcapresp= {0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};/*START_CAPTURE_REP    =   0x0004; /**< ID of StartCaptureReply */
						0x00 };/* START_CAPTURE_REP = 0x0004; /**< ID of StartCaptureReply */


	        	if (!ComponentCollectionFilter2Port.isEmpty()) {
	        	if (!ComponentCollectionFilter2Port.isEmpty()) {
	    			
	    			
@@ -207,10 +212,8 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
	    				try{
	    				try{
		    				String key = (String) keys.nextElement();
		    				String key = (String) keys.nextElement();
	    					FilterPackets fp = ComponentCollectionFilter2Port.get(key);
	    					FilterPackets fp = ComponentCollectionFilter2Port.get(key);
							log.info("StartCaptureREQ: launch ReadCaptureThread for component "
		    				log.info("StartCaptureREQ: launch ReadCaptureThread for component " + fp.componentId.getComponentName());
									+ fp.componentId.getComponentName());
		    				ReadCaptureThread t = new ReadCaptureThread (fp.componentId.getComponentName(),log, tracefile,fp);
							ReadCaptureThread t = new ReadCaptureThread(fp.componentId.getComponentName(), log,
									tracefile, fp);
		    			    t.join(1000);
		    			    t.join(1000);
		    				Thread.sleep(100);
		    				Thread.sleep(100);
	    				}catch(Exception e){
	    				}catch(Exception e){
@@ -226,8 +229,7 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
	               	
	               	
	        case 5:/*STOP_CAPTURE_REQ    =   0x0005; /**< ID of StopCaptureRequest */
	        case 5:/*STOP_CAPTURE_REQ    =   0x0005; /**< ID of StopCaptureRequest */
	        	log.info("StopCaptureREQ");
	        	log.info("StopCaptureREQ");
				byte[] stopcapresp = { 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
	        	byte[] stopcapresp= {0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};/*STOP_CAPTURE_REP     =   0x0006; /**< ID of StopCaptureReply */
						0x00 };/* STOP_CAPTURE_REP = 0x0006; /**< ID of StopCaptureReply */
	        	
	        	
	        	if (!ComponentCollectionFilter2Port.isEmpty()) {
	        	if (!ComponentCollectionFilter2Port.isEmpty()) {
	    			
	    			
@@ -264,10 +266,9 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
				if (componentId.getComponentName().equals("MTC")){
				if (componentId.getComponentName().equals("MTC")){
					//result = send(packet);
					//result = send(packet);
				    result = true;
				    result = true;
				} else {
				}
					// for selection sequence to which PTC first send resonse //FILTER_REQ -
				else{
					// FILTER_REP
					//for selection sequence to which PTC first send resonse //FILTER_REQ - FILTER_REP
					//log.debug(FilterMsgFIFO.size());
					//FilterMsgFIFO.add(componentId);
					//FilterMsgFIFO.add(componentId);
					//result = send(packet);
					//result = send(packet);
					result = true;
					result = true;
@@ -298,8 +299,7 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
			
			
			if(tsiPortId.getPortName().equals("acPort")){
			if(tsiPortId.getPortName().equals("acPort")){
				if (comPortId.getComponent().getComponentName().equals("MTC")){
				if (comPortId.getComponent().getComponentName().equals("MTC")){
					// ComponentCollection.remove(comPortId.getComponent().getComponentName(),
				   //ComponentCollection.remove(comPortId.getComponent().getComponentName(), tsiPortId);
					// tsiPortId);
			       result = true;//disconnect();
			       result = true;//disconnect();
				}else{
				}else{
				   ComponentCollection.remove(comPortId.getComponent().getComponentName(), tsiPortId);
				   ComponentCollection.remove(comPortId.getComponent().getComponentName(), tsiPortId);
@@ -307,17 +307,20 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
				   //log.debug(ComponentCollection.elements().toString());
				   //log.debug(ComponentCollection.elements().toString());
				   result = true; //assume MTC acport was successfully connected
				   result = true; //assume MTC acport was successfully connected
				}
				}
			} else if (tsiPortId.getPortName().equals("sipPort")) {
			}else
			    if (tsiPortId.getPortName().equals("sipPort")){
			    	ComponentCollection.remove(comPortId.getComponent().getComponentName(), tsiPortId);
			    	ComponentCollection.remove(comPortId.getComponent().getComponentName(), tsiPortId);
			    	ComponentCollectionCompPort.remove(comPortId.getComponent().getComponentName()+"-data", comPortId);
			    	ComponentCollectionCompPort.remove(comPortId.getComponent().getComponentName()+"-data", comPortId);
					//log.debug(ComponentCollection.elements().toString());
					//log.debug(ComponentCollection.elements().toString());
					result = true; //assume MTC acport was successfully connected
					result = true; //assume MTC acport was successfully connected
			} else if (tsiPortId.getPortName().equals("diameterPort")) {
			}else
			    if (tsiPortId.getPortName().equals("diameterPort")){
			    	ComponentCollection.remove(comPortId.getComponent().getComponentName(), tsiPortId);
			    	ComponentCollection.remove(comPortId.getComponent().getComponentName(), tsiPortId);
			    	ComponentCollectionCompPort.remove(comPortId.getComponent().getComponentName()+"-data", comPortId);
			    	ComponentCollectionCompPort.remove(comPortId.getComponent().getComponentName()+"-data", comPortId);
					//log.debug(ComponentCollection.elements().toString());
					//log.debug(ComponentCollection.elements().toString());
					result = true; //assume MTC acport was successfully connected
					result = true; //assume MTC acport was successfully connected
			} else if (tsiPortId.getPortName().equals("dPort")) {
			}else
			    if (tsiPortId.getPortName().equals("dPort")){
			    	ComponentCollection.remove(comPortId.getComponent().getComponentName(), tsiPortId);
			    	ComponentCollection.remove(comPortId.getComponent().getComponentName(), tsiPortId);
			    	ComponentCollectionCompPort.remove(comPortId.getComponent().getComponentName()+"-d", comPortId);
			    	ComponentCollectionCompPort.remove(comPortId.getComponent().getComponentName()+"-d", comPortId);
					//log.debug(ComponentCollection.elements().toString());
					//log.debug(ComponentCollection.elements().toString());
@@ -345,7 +348,7 @@ public class IotConnectionOffline extends Thread/* PCAP */ implements LocalAdapt
		
		
		int iotmsg = ((buffer[0] & 0xFF))|((buffer[1] & 0xFF) << 8);//iot message type
		int iotmsg = ((buffer[0] & 0xFF))|((buffer[1] & 0xFF) << 8);//iot message type
		byte[] message = new byte[packetLength];
		byte[] message = new byte[packetLength];
		log.debug("IOT MSG TYPE "+iotmsg);
		
		if (iotmsg==1){ //CAPTURE_DATA_IND
		if (iotmsg==1){ //CAPTURE_DATA_IND
			byte[] packetb = new byte[packetLength-0x1b];
			byte[] packetb = new byte[packetLength-0x1b];
			System.arraycopy(buffer,0x1b, packetb, 0, packetLength-0x1b);
			System.arraycopy(buffer,0x1b, packetb, 0, packetLength-0x1b);