Rev

Rev 2230 | Details | Compare with Previous | Last modification | View Log | SVN | Bug Tracker

Rev Author Line No. Line
413 berge 1
/**
417 berge 2
 *  BTP port implementation
3
 *  
4
 *  @author     ETSI / STF424
5
 *  @version    $URL: file:///D:/RepositoriesNew/ITS/trunk/javasrc/adapter/org/etsi/its/adapter/ports/BtpPort.java $
6
 *              $Id: BtpPort.java 2655 2017-01-26 10:46:08Z filatov $
413 berge 7
 *
8
 */
334 berge 9
package org.etsi.its.adapter.ports;
10
 
2230 mullers 11
import java.util.HashMap;
479 berge 12
import java.util.Map;
334 berge 13
 
2230 mullers 14
import org.etsi.common.ByteHelper;
15
import org.etsi.its.adapter.layers.BtpLayer;
16
import org.etsi.its.adapter.layers.GnLayer;
17
 
417 berge 18
/**
19
 *  BTP port implementation
20
 */  
334 berge 21
public class BtpPort extends ProtocolPort {
22
 
2230 mullers 23
    /**
24
     * Constructor
417 berge 25
     * @param   portName        Name of the port
26
     * @param   componentName   Name of the component owning this port instance
27
     * @param   lowerStackDesc  Description of the port's lower stack in the form "Layer/Layer/Layer/..."
634 berge 28
     * @param  linkLayerAddress    Link-layer address to be used by this port as source address (null if not applicable)
2230 mullers 29
     */
30
    public BtpPort(String portName, String componentName, String lowerStackDesc, String linkLayerAddress) {
31
        super(portName, componentName, lowerStackDesc, linkLayerAddress);
32
    }
334 berge 33
 
2230 mullers 34
    /* (non-Javadoc)
35
     * @see org.etsi.its.adapter.ports.ProtocolPort#receive(byte[])
36
     */
37
    @Override
38
    public void receive(byte[] message, Map<String, Object> lowerInfo) {
39
 
40
        // Encode with GN next header info - BTP A or BTP B
41
        byte[] msgInd = ByteHelper.concat(
2655 filatov 42
                new byte[] { ((Byte)(lowerInfo.get(GnLayer.GN_NEXTHEADER))).byteValue() },
2230 mullers 43
                message
44
            );
45
        super.receive(msgInd, lowerInfo);
46
    }
47
 
48
    /* (non-Javadoc)
49
     * @see org.etsi.its.adapter.ports.IPort#send(byte[])
50
     */
51
    @Override
52
    public boolean send(byte[] message) {
53
 
54
        HashMap<String, Object> params = new HashMap<String, Object>();
55
        switch (message[0]) {
56
            case 1:
57
                params.put(BtpLayer.BTP_TYPE, BtpLayer.TYPE_A);
58
                params.put(GnLayer.GN_NEXTHEADER, "BTP-A");
59
                break;
60
            case 2:
61
                params.put(BtpLayer.BTP_TYPE, BtpLayer.TYPE_B);
62
                params.put(GnLayer.GN_NEXTHEADER, "BTP-B");
63
                break;
64
            default:
65
                //otherwise GN next header is ANY
66
                break;
67
        }
68
        params.put(BtpLayer.BTP_DSTPORT, 2001);
69
        params.put(BtpLayer.BTP_SRCPORT, 500);
70
        params.put(GnLayer.GN_TYPE, GnLayer.HT_TSB);
71
        params.put(GnLayer.GN_SUBTYPE, GnLayer.HST_MULTIHOP);
72
 
73
        byte[] msg2sent = new byte[message.length-1];
74
        //cut the next header indication byte
75
        System.arraycopy(message, 1, msg2sent, 0, msg2sent.length);
76
 
77
        return send(msg2sent, params);
78
    }
334 berge 79
}