Search in sources :

Example 1 with IPFilterRule

use of net.java.slee.resource.diameter.base.events.avp.IPFilterRule in project jain-slee.diameter by RestComm.

the class IPFilterRuleTest method testGetters2.

@Test
public void testGetters2() {
    IPFilterRule rule = new IPFilterRule("deny in ip from !assigned to 192.1.1.1/0 6,3 frag established setup tcpoptions mrss icmptypes 0,3,4,5");
    Assert.assertEquals("Action does not match!", IPFilterRule.ACTION_DENY, rule.getAction());
    Assert.assertEquals("Direction does not match!", IPFilterRule.DIR_IN, rule.getDirection());
    // 0 is ip?
    Assert.assertEquals("Protocol does not match!", 0, rule.getProtocol());
    // this is a bit confusing...
    Assert.assertEquals("Any does not match!", true, rule.isAnyProtocol());
    Assert.assertEquals("SrcAssign does not match!", true, rule.isSourceAssignedIps());
    Assert.assertEquals("SrcNoMatch does not match!", true, rule.isSourceNoMatch());
    Assert.assertEquals("DstAssign does not match!", false, rule.isDestAssignedIps());
    Assert.assertEquals("DstNoMatch does not match!", false, rule.isDestNoMatch());
    Assert.assertEquals("SrcBits does not match!", -1, rule.getSourceBits());
    Assert.assertEquals("DstBits does not match!", 0, rule.getDestBits());
    Assert.assertEquals("SrcAddr does not match", null, rule.getSourceIp());
    Assert.assertEquals("DstAddr does not match", "192.1.1.1", rule.getDestIp());
    // ports
    int[][] sourcePorts = rule.getSourcePorts();
    Assert.assertNull("No source ports!", sourcePorts);
    int[][] destPorts = rule.getDestPorts();
    int[][] expectedDestPorts = new int[][] { new int[] { 6, 6 }, new int[] { 3, 3 } };
    Assert.assertNotNull("No dest ports!", destPorts);
    Assert.assertEquals("Dest ports len does not match!", expectedDestPorts.length, destPorts.length);
    for (int index = 0; index < expectedDestPorts.length; index++) {
        Assert.assertTrue("Dest ports entry[" + index + "] does not match!", Arrays.equals(expectedDestPorts[index], destPorts[index]));
    }
    // options
    Assert.assertEquals("Expected fragment", true, rule.isFragment());
    Assert.assertEquals("Expected established", true, rule.isEstablished());
    Assert.assertEquals("Expected setup", true, rule.isSetup());
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getIcmpTypes(), new String[] { "0", "3", "4", "5" }));
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getNumericIcmpTypes(), EMPTY_INT_ARRAY));
    Assert.assertTrue("Wrong tcpflags option", Arrays.equals(rule.getTcpFlags(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong tcpoptions option", Arrays.equals(rule.getTcpOptions(), new String[] { "mrss" }));
    Assert.assertTrue("Wrong opoptions option", Arrays.equals(rule.getIpOptions(), EMPTY_STRING_ARRAY));
}
Also used : IPFilterRule(net.java.slee.resource.diameter.base.events.avp.IPFilterRule) Test(org.junit.Test)

Example 2 with IPFilterRule

use of net.java.slee.resource.diameter.base.events.avp.IPFilterRule in project jain-slee.diameter by RestComm.

the class IPFilterRuleTest method testGetters4.

// here we test options, if proper flags are lit
@Test
public void testGetters4() {
    IPFilterRule rule = new IPFilterRule("permit out 2 from 2001:0db8:85a3:0000:0000:8a2e:0370:7334/32 to fe80:0:0:0:202:b3ff:fe1e:8329/24 2345 frag");
    // options
    Assert.assertEquals("Expected fragment", true, rule.isFragment());
    Assert.assertEquals("Expected established", false, rule.isEstablished());
    Assert.assertEquals("Expected setup", false, rule.isSetup());
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getIcmpTypes(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getNumericIcmpTypes(), EMPTY_INT_ARRAY));
    Assert.assertTrue("Wrong tcpflags option", Arrays.equals(rule.getTcpFlags(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong tcpoptions option", Arrays.equals(rule.getTcpOptions(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong opoptions option", Arrays.equals(rule.getIpOptions(), EMPTY_STRING_ARRAY));
    rule = new IPFilterRule("permit out 2 from 2001:0db8:85a3:0000:0000:8a2e:0370:7334/32 to fe80:0:0:0:202:b3ff:fe1e:8329/24 2345 setup");
    // options
    Assert.assertEquals("Expected fragment", false, rule.isFragment());
    Assert.assertEquals("Expected established", false, rule.isEstablished());
    Assert.assertEquals("Expected setup", true, rule.isSetup());
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getIcmpTypes(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getNumericIcmpTypes(), EMPTY_INT_ARRAY));
    Assert.assertTrue("Wrong tcpflags option", Arrays.equals(rule.getTcpFlags(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong tcpoptions option", Arrays.equals(rule.getTcpOptions(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong opoptions option", Arrays.equals(rule.getIpOptions(), EMPTY_STRING_ARRAY));
    rule = new IPFilterRule("permit out 2 from 2001:0db8:85a3:0000:0000:8a2e:0370:7334/32 to fe80:0:0:0:202:b3ff:fe1e:8329/24 2345 established");
    // options
    Assert.assertEquals("Expected fragment", false, rule.isFragment());
    Assert.assertEquals("Expected established", true, rule.isEstablished());
    Assert.assertEquals("Expected setup", false, rule.isSetup());
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getIcmpTypes(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getNumericIcmpTypes(), EMPTY_INT_ARRAY));
    Assert.assertTrue("Wrong tcpflags option", Arrays.equals(rule.getTcpFlags(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong tcpoptions option", Arrays.equals(rule.getTcpOptions(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong opoptions option", Arrays.equals(rule.getIpOptions(), EMPTY_STRING_ARRAY));
}
Also used : IPFilterRule(net.java.slee.resource.diameter.base.events.avp.IPFilterRule) Test(org.junit.Test)

Example 3 with IPFilterRule

use of net.java.slee.resource.diameter.base.events.avp.IPFilterRule in project jain-slee.diameter by RestComm.

the class SDPConverter method convertSDP.

/**
 * Returns the value of the Media-Component-Description[] AVP, of type Grouped.
 */
public static MediaComponentDescription[] convertSDP(GqProvider gqProvider, String sourceSDP, String destinationSDP) throws SdpException, SdpParseException {
    SdpFactory sdpFactory = SdpFactory.getInstance();
    SessionDescription sourceSessionDescription = sdpFactory.createSessionDescription(sourceSDP);
    SessionDescription destinationSessionDescription = sdpFactory.createSessionDescription(destinationSDP);
    Vector<MediaDescription> sourceMediaDescriptions = sourceSessionDescription.getMediaDescriptions(false);
    Vector<MediaDescription> destinationMediaDescriptions = destinationSessionDescription.getMediaDescriptions(false);
    Vector<AttributeField> attributes;
    Vector<BandwidthField> bandwidth;
    Vector<MediaComponentDescription> mediaComponentDescriptions = new Vector<MediaComponentDescription>();
    Vector<MediaSubComponent[]> mediaSubComponents = new Vector<MediaSubComponent[]>();
    GqAvpFactory avpFactory = gqProvider.getGqAvpFactory();
    MediaComponentDescription currDescription = null;
    Media currMedia;
    String mediaType;
    String codecLine;
    String mode;
    if (sourceMediaDescriptions == null)
        throw new SdpParseException(0, 0, "no source media found");
    if (destinationMediaDescriptions == null)
        throw new SdpParseException(0, 0, "no destination media found");
    String proto;
    int dataPort;
    int rtcpPort;
    int ports;
    int step;
    String dataAddress;
    String rtcpAddress;
    MediaSubComponent currSubComponent;
    IPFilterRule currFlowDescription;
    String[] rtcpValues;
    for (int i = 0; i < sourceMediaDescriptions.size(); i++) {
        attributes = sourceMediaDescriptions.get(i).getAttributes(false);
        bandwidth = sourceMediaDescriptions.get(i).getBandwidths(false);
        currMedia = sourceMediaDescriptions.get(i).getMedia();
        currDescription = avpFactory.createMediaComponentDescription();
        mediaType = currMedia.getMediaType().toLowerCase();
        if (mediaType.equals("audio"))
            currDescription.setMediaType(MediaType.AUDIO);
        else if (mediaType.equals("video"))
            currDescription.setMediaType(MediaType.VIDEO);
        else if (mediaType.equals("control"))
            currDescription.setMediaType(MediaType.CONTROL);
        else if (mediaType.equals("application"))
            currDescription.setMediaType(MediaType.APPLICATION);
        else if (mediaType.equals("message"))
            currDescription.setMediaType(MediaType.MESSAGE);
        else if (mediaType.equals("data"))
            currDescription.setMediaType(MediaType.DATA);
        else if (mediaType.equals("text"))
            currDescription.setMediaType(MediaType.TEXT);
        else
            currDescription.setMediaType(MediaType.OTHER);
        codecLine = "downlink" + System.getProperty("line.separator");
        codecLine = codecLine + "offer" + System.getProperty("line.separator");
        codecLine = codecLine + currMedia.toString() + System.getProperty("line.separator");
        mode = "";
        dataPort = currMedia.getMediaPort();
        rtcpPort = currMedia.getMediaPort() + 1;
        if (sourceMediaDescriptions.get(i).getConnection() != null)
            rtcpAddress = sourceMediaDescriptions.get(i).getConnection().getAddress();
        else
            rtcpAddress = sourceSessionDescription.getConnection().getAddress();
        dataAddress = rtcpAddress;
        proto = currMedia.getProtocol().toLowerCase();
        ports = 1;
        step = 2;
        if (currMedia.getPortCount() > 0)
            ports = currMedia.getPortCount();
        if (attributes != null)
            for (int j = 0; j < attributes.size(); j++) if (attributes.get(j).getName().equals("recvonly"))
                mode = "recvonly";
            else if (attributes.get(j).getName().equals("sendonly"))
                mode = "sendonly";
            else if (attributes.get(j).getName().equals("sendrecv"))
                mode = "sendrecv";
            else if (attributes.get(j).getName().equals("inactive"))
                mode = "inactive";
            else if (attributes.get(j).getName().equals("rtcp")) {
                rtcpValues = attributes.get(j).getValue().split(" ");
                rtcpPort = Integer.parseInt(rtcpValues[0]);
                if (rtcpPort != dataPort + 1)
                    step = 1;
                if (rtcpValues.length == 3)
                    rtcpAddress = rtcpValues[2];
            } else
                codecLine += attributes.get(j).toString() + System.getProperty("line.separator");
        if (proto.equals("rtp/avp")) {
            mediaSubComponents.add(new MediaSubComponent[ports * 2]);
            // 2 flows
            if (!mode.equals("recvonly")) {
                for (int j = 0; j < ports; j++) {
                    currSubComponent = avpFactory.createMediaSubComponent();
                    currSubComponent.setFlowNumber(1 + j * ports);
                    currFlowDescription = new IPFilterRule("permit in 17 from " + dataAddress + " " + (dataPort + j * step) + " to any");
                    currSubComponent.setFlowDescription(currFlowDescription);
                    mediaSubComponents.get(i)[0 + j * ports] = currSubComponent;
                }
            }
            for (int j = 0; j < ports; j++) {
                currSubComponent = avpFactory.createMediaSubComponent();
                currSubComponent.setFlowNumber(2 + j * ports);
                currSubComponent.setFlowUsage(FlowUsage.RTCP);
                currFlowDescription = new IPFilterRule("permit in 17 from " + rtcpAddress + " " + (rtcpPort + j * step) + " to any");
                currSubComponent.setFlowDescription(currFlowDescription);
                mediaSubComponents.get(i)[1 + j * ports] = currSubComponent;
            }
        } else if (proto.equals("udp")) {
            // 1 flow
            if (!mode.equals("recvonly")) {
                for (int j = 0; j < ports; j++) {
                    currSubComponent = avpFactory.createMediaSubComponent();
                    currSubComponent.setFlowNumber(1 + j * ports);
                    currFlowDescription = new IPFilterRule("permit in 17 from " + dataAddress + " " + (dataPort + j * step) + " to any");
                    currSubComponent.setFlowDescription(currFlowDescription);
                    mediaSubComponents.get(i)[0 + j * ports] = currSubComponent;
                }
            }
        } else if (proto.equals("rtp/avp-tcp") || proto.equals("tcp/rtp/avp")) {
            // 2 flows
            if (!mode.equals("recvonly")) {
                for (int j = 0; j < ports; j++) {
                    currSubComponent = avpFactory.createMediaSubComponent();
                    currSubComponent.setFlowNumber(1 + j * ports);
                    currFlowDescription = new IPFilterRule("permit in 6 from " + dataAddress + " " + (dataPort + j * step) + " to any");
                    currSubComponent.setFlowDescription(currFlowDescription);
                    mediaSubComponents.get(i)[0 + j * ports] = currSubComponent;
                }
            }
            for (int j = 0; j < ports; j++) {
                currSubComponent = avpFactory.createMediaSubComponent();
                currSubComponent.setFlowNumber(2 + j * ports);
                currSubComponent.setFlowUsage(FlowUsage.RTCP);
                currFlowDescription = new IPFilterRule("permit in 6 from " + rtcpAddress + " " + (rtcpPort + j * step) + " to any");
                currSubComponent.setFlowDescription(currFlowDescription);
                mediaSubComponents.get(i)[1 + j * ports] = currSubComponent;
            }
        } else if (proto.equals("tcp")) {
            // 1 flow
            if (!mode.equals("recvonly")) {
                for (int j = 0; j < ports; j++) {
                    currSubComponent = avpFactory.createMediaSubComponent();
                    currSubComponent.setFlowNumber(1 + j * ports);
                    currFlowDescription = new IPFilterRule("permit in 6 from " + dataAddress + " " + (dataPort + j * step) + " to any");
                    currSubComponent.setFlowDescription(currFlowDescription);
                    mediaSubComponents.get(i)[0 + j * ports] = currSubComponent;
                }
            }
        } else if (proto.equals("rtp/avp-dccp") || proto.equals("dccp/rtp/avp")) {
            // 2 flows
            if (!mode.equals("recvonly")) {
                for (int j = 0; j < ports; j++) {
                    currSubComponent = avpFactory.createMediaSubComponent();
                    currSubComponent.setFlowNumber(1 + j * ports);
                    currFlowDescription = new IPFilterRule("permit in 33 from " + dataAddress + " " + (dataPort + j * step) + " to any");
                    currSubComponent.setFlowDescription(currFlowDescription);
                    mediaSubComponents.get(i)[0 + j * ports] = currSubComponent;
                }
            }
            for (int j = 0; j < ports; j++) {
                currSubComponent = avpFactory.createMediaSubComponent();
                currSubComponent.setFlowNumber(2 + j * ports);
                currSubComponent.setFlowUsage(FlowUsage.RTCP);
                currFlowDescription = new IPFilterRule("permit in 33 from " + rtcpAddress + " " + (rtcpPort + j * step) + " to any");
                currSubComponent.setFlowDescription(currFlowDescription);
                mediaSubComponents.get(i)[1 + j * ports] = currSubComponent;
            }
        } else if (proto.equals("dccp")) {
            // 1 flow
            if (!mode.equals("recvonly")) {
                for (int j = 0; j < ports; j++) {
                    currSubComponent = avpFactory.createMediaSubComponent();
                    currSubComponent.setFlowNumber(1 + j * ports);
                    currFlowDescription = new IPFilterRule("permit in 33 from " + dataAddress + " " + (dataPort + j * step) + " to any");
                    currSubComponent.setFlowDescription(currFlowDescription);
                    mediaSubComponents.get(i)[0 + j * ports] = currSubComponent;
                }
            }
        } else
            throw new SdpParseException(0, 0, "protocol not supported " + proto);
        if (bandwidth != null)
            for (int j = 0; j < bandwidth.size(); j++) if (bandwidth.get(j).getType().equals("AS"))
                currDescription.setMaxRequestedBandwidthDL(bandwidth.get(j).getValue());
            else if (bandwidth.get(j).getType().equals("RR"))
                currDescription.setRRBandwidth(bandwidth.get(j).getValue());
            else if (bandwidth.get(j).getType().equals("RS"))
                currDescription.setRSBandwidth(bandwidth.get(j).getValue());
            else
                codecLine += bandwidth.get(j).toString() + System.getProperty("line.separator");
        currDescription.setCodecData(codecLine.getBytes());
        if (currMedia.getMediaPort() == 0)
            currDescription.setFlowStatus(FlowStatus.REMOVED);
        else if (mode.equals("recvonly"))
            currDescription.setFlowStatus(FlowStatus.ENABLED_DOWNLINK);
        else if (mode.equals("sendonly"))
            currDescription.setFlowStatus(FlowStatus.ENABLED_UPLINK);
        else if (mode.equals("inactive"))
            currDescription.setFlowStatus(FlowStatus.DISABLED);
        else
            currDescription.setFlowStatus(FlowStatus.ENABLED);
        currDescription.setMediaComponentNumber(i + 1);
        mediaComponentDescriptions.add(currDescription);
    }
    Boolean found = false;
    for (int i = 0; i < destinationMediaDescriptions.size(); i++) {
        found = false;
        currMedia = destinationMediaDescriptions.get(i).getMedia();
        mediaType = currMedia.getMediaType().toLowerCase();
        attributes = destinationMediaDescriptions.get(i).getAttributes(false);
        bandwidth = destinationMediaDescriptions.get(i).getBandwidths(false);
        codecLine = "uplink" + System.getProperty("line.separator");
        codecLine = codecLine + "answer" + System.getProperty("line.separator");
        codecLine = codecLine + currMedia.toString() + System.getProperty("line.separator");
        for (int j = 0; j < mediaComponentDescriptions.size(); j++) if (mediaComponentDescriptions.get(j).getMediaType().toString().toLowerCase().equals(mediaType)) {
            currDescription = mediaComponentDescriptions.get(j);
            found = true;
            break;
        }
        if (found) {
            dataPort = currMedia.getMediaPort();
            rtcpPort = currMedia.getMediaPort() + 1;
            if (destinationMediaDescriptions.get(i).getConnection() != null)
                rtcpAddress = destinationMediaDescriptions.get(i).getConnection().getAddress();
            else
                rtcpAddress = destinationSessionDescription.getConnection().getAddress();
            dataAddress = rtcpAddress;
            proto = currMedia.getProtocol().toLowerCase();
            ports = 1;
            step = 2;
            if (currMedia.getPortCount() > 0)
                ports = currMedia.getPortCount();
            mode = "";
            if (attributes != null)
                for (int j = 0; j < attributes.size(); j++) if (attributes.get(j).getName().equals("recvonly"))
                    mode = "recvonly";
                else if (attributes.get(j).getName().equals("sendonly"))
                    mode = "sendonly";
                else if (attributes.get(j).getName().equals("sendrecv"))
                    mode = "sendrecv";
                else if (attributes.get(j).getName().equals("inactive"))
                    mode = "inactive";
                else if (attributes.get(j).getName().equals("rtcp")) {
                    rtcpValues = attributes.get(j).getValue().split(" ");
                    rtcpPort = Integer.parseInt(rtcpValues[0]);
                    if (rtcpPort != dataPort + 1)
                        step = 1;
                    if (rtcpValues.length == 3)
                        rtcpAddress = rtcpValues[2];
                } else
                    codecLine += attributes.get(j).toString() + System.getProperty("line.separator");
            if (proto.equals("rtp/avp")) {
                // 2 flows
                if (!mode.equals("sendonly")) {
                    for (int j = 0; j < ports; j++) {
                        currFlowDescription = new IPFilterRule("permit out 17 from any to " + dataAddress + " " + (dataPort + j * step));
                        mediaSubComponents.get(i)[0 + j * ports].setFlowDescription(currFlowDescription);
                    }
                }
                for (int j = 0; j < ports; j++) {
                    currFlowDescription = new IPFilterRule("permit out 17 from any to " + rtcpAddress + " " + (rtcpPort + j * step));
                    mediaSubComponents.get(i)[1 + j * ports].setFlowDescription(currFlowDescription);
                }
            } else if (proto.equals("udp")) {
                // 1 flow
                if (!mode.equals("sendonly")) {
                    for (int j = 0; j < ports; j++) {
                        currFlowDescription = new IPFilterRule("permit out 17 from any to " + dataAddress + " " + (dataPort + j * step));
                        mediaSubComponents.get(i)[0 + j * ports].setFlowDescription(currFlowDescription);
                    }
                }
            } else if (proto.equals("rtp/avp-tcp") || proto.equals("tcp/rtp/avp")) {
                // 2 flows
                if (!mode.equals("sendonly")) {
                    for (int j = 0; j < ports; j++) {
                        currFlowDescription = new IPFilterRule("permit out 6 from any to " + dataAddress + " " + (dataPort + j * step));
                        mediaSubComponents.get(i)[0 + j * ports].setFlowDescription(currFlowDescription);
                    }
                }
                for (int j = 0; j < ports; j++) {
                    currFlowDescription = new IPFilterRule("permit out 6 from any to " + rtcpAddress + " " + (rtcpPort + j * step));
                    mediaSubComponents.get(i)[1 + j * ports].setFlowDescription(currFlowDescription);
                }
            } else if (proto.equals("tcp")) {
                // 1 flow
                if (!mode.equals("sendonly")) {
                    for (int j = 0; j < ports; j++) {
                        currFlowDescription = new IPFilterRule("permit out 6 from any to " + dataAddress + " " + (dataPort + j * step));
                        mediaSubComponents.get(i)[0 + j * ports].setFlowDescription(currFlowDescription);
                    }
                }
            } else if (proto.equals("rtp/avp-dccp") || proto.equals("dccp/rtp/avp")) {
                // 2 flows
                if (!mode.equals("sendonly")) {
                    for (int j = 0; j < ports; j++) {
                        currFlowDescription = new IPFilterRule("permit out 33 from any to " + dataAddress + " " + (dataPort + j * step));
                        mediaSubComponents.get(i)[0 + j * ports].setFlowDescription(currFlowDescription);
                    }
                }
                for (int j = 0; j < ports; j++) {
                    currFlowDescription = new IPFilterRule("permit out 33 from any to " + rtcpAddress + " " + (rtcpPort + j * step));
                    mediaSubComponents.get(i)[1 + j * ports].setFlowDescription(currFlowDescription);
                }
            } else if (proto.equals("dccp")) {
                // 1 flow
                if (!mode.equals("sendonly")) {
                    for (int j = 0; j < ports; j++) {
                        currFlowDescription = new IPFilterRule("permit out 33 from any to " + dataAddress + " " + (dataPort + j * step));
                        mediaSubComponents.get(i)[0 + j * ports].setFlowDescription(currFlowDescription);
                    }
                }
            } else
                throw new SdpParseException(0, 0, "protocol not supported " + proto);
            if (bandwidth != null)
                for (int j = 0; j < bandwidth.size(); j++) if (bandwidth.get(j).getType().equals("AS"))
                    currDescription.setMaxRequestedBandwidthUL(bandwidth.get(j).getValue());
                else if (bandwidth.get(j).getType().equals("RR")) {
                // do nothing
                } else if (bandwidth.get(j).getType().equals("RS")) {
                // do nothing
                } else
                    codecLine += bandwidth.get(j).toString() + System.getProperty("line.separator");
            currDescription.setMediaSubComponents(mediaSubComponents.get(i));
            currDescription.setCodecData(codecLine.getBytes());
        }
    }
    return mediaComponentDescriptions.toArray(new MediaComponentDescription[mediaComponentDescriptions.size()]);
}
Also used : SessionDescription(javax.sdp.SessionDescription) IPFilterRule(net.java.slee.resource.diameter.base.events.avp.IPFilterRule) MediaDescription(javax.sdp.MediaDescription) AttributeField(gov.nist.javax.sdp.fields.AttributeField) Media(javax.sdp.Media) GqAvpFactory(net.java.slee.resource.diameter.gq.GqAvpFactory) MediaComponentDescription(net.java.slee.resource.diameter.gq.events.avp.MediaComponentDescription) SdpParseException(javax.sdp.SdpParseException) MediaSubComponent(net.java.slee.resource.diameter.gq.events.avp.MediaSubComponent) BandwidthField(gov.nist.javax.sdp.fields.BandwidthField) SdpFactory(javax.sdp.SdpFactory) Vector(java.util.Vector)

Example 4 with IPFilterRule

use of net.java.slee.resource.diameter.base.events.avp.IPFilterRule in project jain-slee.diameter by RestComm.

the class RxFactoriesTest method testMediaComponentDescription.

@Test
public void testMediaComponentDescription() {
    AARequest aar = rxMessageFactory.createAARequest();
    MediaComponentDescriptionAvp mcdAvp = rxAvpFactory.createMediaComponentDescription();
    MediaSubComponentAvp mscAvp = rxAvpFactory.createMediaSubComponent();
    mscAvp.setFlowUsage(FlowUsage.AF_SIGNALLING);
    IPFilterRule fd1Avp = new IPFilterRule("permit in ip from 192.168.0.0/24 10,11,12,20-30 to 192.168.1.1 99 frag established");
    IPFilterRule fd2Avp = new IPFilterRule("permit out 2 from 192.1.0.0/24 to 192.1.1.1/0 frag established setup tcpoptions mrss");
    IPFilterRule fd3Avp = new IPFilterRule("permit out 4 from 10.0.1.91 4060 to 10.0.0.190 43772 ");
    mscAvp.setFlowDescriptions(new IPFilterRule[] { fd1Avp, fd2Avp, fd3Avp });
    mcdAvp.setMediaSubComponent(mscAvp);
    aar.setMediaComponentDescription(mcdAvp);
    // from Richard Good
    if (aar.hasMediaComponentDescription()) {
        System.err.println("Has media component description");
        MediaComponentDescriptionAvp[] mcd = aar.getMediaComponentDescriptions();
        if (mcd[0].hasMediaSubComponent()) {
            System.err.println("Has media sub component");
            MediaSubComponentAvp[] msc = mcd[0].getMediaSubComponents();
            if (msc[0].hasFlowUsage()) {
                System.err.println("Has flow usage");
            }
            System.err.println("msc[0] flow usage: " + msc[0].getFlowUsage());
            System.err.println("msc[0] flow usage value: " + msc[0].getFlowUsage().getValue());
            // other from Richarg Good
            IPFilterRule[] ipf = msc[0].getFlowDescriptions();
            System.err.println("msc[0] flow descriptions " + ipf.toString());
            System.err.println("msc[0] flow description length " + ipf.length);
            for (int b = 0; b < ipf.length; b++) {
                // THIS DOES NOT PRINT!
                System.err.println("msc[0] flow description " + ipf[b].toString());
            }
        }
    }
}
Also used : MediaComponentDescriptionAvp(net.java.slee.resource.diameter.rx.events.avp.MediaComponentDescriptionAvp) IPFilterRule(net.java.slee.resource.diameter.base.events.avp.IPFilterRule) AARequest(net.java.slee.resource.diameter.rx.events.AARequest) MediaSubComponentAvp(net.java.slee.resource.diameter.rx.events.avp.MediaSubComponentAvp) Test(org.junit.Test) BaseFactoriesTest(org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)

Example 5 with IPFilterRule

use of net.java.slee.resource.diameter.base.events.avp.IPFilterRule in project jain-slee.diameter by RestComm.

the class IPFilterRuleTest method testGetters3.

@Test
public void testGetters3() {
    IPFilterRule rule = new IPFilterRule("permit out 2 from 2001:0db8:85a3:0000:0000:8a2e:0370:7334/32 to fe80:0:0:0:202:b3ff:fe1e:8329/24 2345");
    Assert.assertEquals("Action does not match!", IPFilterRule.ACTION_PERMIT, rule.getAction());
    Assert.assertEquals("Direction does not match!", IPFilterRule.DIR_OUT, rule.getDirection());
    // 0 is ip?
    Assert.assertEquals("Protocol does not match!", 2, rule.getProtocol());
    // this is a bit confusing...
    Assert.assertEquals("Any does not match!", false, rule.isAnyProtocol());
    Assert.assertEquals("SrcAssign does not match!", false, rule.isSourceAssignedIps());
    Assert.assertEquals("SrcNoMatch does not match!", false, rule.isSourceNoMatch());
    Assert.assertEquals("DstAssign does not match!", false, rule.isDestAssignedIps());
    Assert.assertEquals("DstNoMatch does not match!", false, rule.isDestNoMatch());
    Assert.assertEquals("SrcBits does not match!", 32, rule.getSourceBits());
    Assert.assertEquals("DstBits does not match!", 24, rule.getDestBits());
    Assert.assertEquals("SrcAddr does not match", "2001:0db8:85a3:0000:0000:8a2e:0370:7334", rule.getSourceIp());
    Assert.assertEquals("DstAddr does not match", "fe80:0:0:0:202:b3ff:fe1e:8329", rule.getDestIp());
    // ports
    int[][] sourcePorts = rule.getSourcePorts();
    Assert.assertNull("No source ports!", sourcePorts);
    int[][] destPorts = rule.getDestPorts();
    int[][] expectedDestPorts = new int[][] { new int[] { 2345, 2345 } };
    Assert.assertNotNull("No dest ports!", destPorts);
    Assert.assertEquals("Dest ports len does not match!", expectedDestPorts.length, destPorts.length);
    for (int index = 0; index < expectedDestPorts.length; index++) {
        Assert.assertTrue("Dest ports entry[" + index + "] does not match!", Arrays.equals(expectedDestPorts[index], destPorts[index]));
    }
    // options
    Assert.assertEquals("Expected fragment", false, rule.isFragment());
    Assert.assertEquals("Expected established", false, rule.isEstablished());
    Assert.assertEquals("Expected setup", false, rule.isSetup());
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getIcmpTypes(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong icmp option", Arrays.equals(rule.getNumericIcmpTypes(), EMPTY_INT_ARRAY));
    Assert.assertTrue("Wrong tcpflags option", Arrays.equals(rule.getTcpFlags(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong tcpoptions option", Arrays.equals(rule.getTcpOptions(), EMPTY_STRING_ARRAY));
    Assert.assertTrue("Wrong opoptions option", Arrays.equals(rule.getIpOptions(), EMPTY_STRING_ARRAY));
}
Also used : IPFilterRule(net.java.slee.resource.diameter.base.events.avp.IPFilterRule) Test(org.junit.Test)

Aggregations

IPFilterRule (net.java.slee.resource.diameter.base.events.avp.IPFilterRule)8 Test (org.junit.Test)6 SdpFactory (javax.sdp.SdpFactory)2 SdpParseException (javax.sdp.SdpParseException)2 SessionDescription (javax.sdp.SessionDescription)2 MediaSubComponent (net.java.slee.resource.diameter.gq.events.avp.MediaSubComponent)2 AttributeField (gov.nist.javax.sdp.fields.AttributeField)1 BandwidthField (gov.nist.javax.sdp.fields.BandwidthField)1 Vector (java.util.Vector)1 Media (javax.sdp.Media)1 MediaDescription (javax.sdp.MediaDescription)1 SdpException (javax.sdp.SdpException)1 GqAvpFactory (net.java.slee.resource.diameter.gq.GqAvpFactory)1 MediaComponentDescription (net.java.slee.resource.diameter.gq.events.avp.MediaComponentDescription)1 AARequest (net.java.slee.resource.diameter.rx.events.AARequest)1 MediaComponentDescriptionAvp (net.java.slee.resource.diameter.rx.events.avp.MediaComponentDescriptionAvp)1 MediaSubComponentAvp (net.java.slee.resource.diameter.rx.events.avp.MediaSubComponentAvp)1 BaseFactoriesTest (org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)1