Search in sources :

Example 6 with IPFilterRule

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

the class IPFilterRuleTest method testGetters1.

@Test
public void testGetters1() {
    IPFilterRule rule = new IPFilterRule("permit out 2 from assigned 34 to 192.1.1.1/0 6,3 frag established setup tcpoptions mrss ipoptions !rr,!ts");
    Assert.assertEquals("Action does not match!", IPFilterRule.ACTION_PERMIT, rule.getAction());
    Assert.assertEquals("Direction does not match!", IPFilterRule.DIR_OUT, rule.getDirection());
    Assert.assertEquals("Protocol does not match!", 2, rule.getProtocol());
    Assert.assertEquals("Any does not match!", false, rule.isAnyProtocol());
    Assert.assertEquals("SrcAssign does not match!", true, 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!", -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();
    int[][] expectedSourcePorts = new int[][] { new int[] { 34, 34 } };
    Assert.assertNotNull("No source ports!", sourcePorts);
    Assert.assertEquals("Source ports len does not match!", expectedSourcePorts.length, sourcePorts.length);
    for (int index = 0; index < expectedSourcePorts.length; index++) {
        Assert.assertTrue("Source ports entry[" + index + "] does not match!", Arrays.equals(expectedSourcePorts[index], sourcePorts[index]));
    }
    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(), 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(), new String[] { "mrss" }));
    Assert.assertTrue("Wrong ipoptions option", Arrays.equals(rule.getIpOptions(), new String[] { "!rr", "!ts" }));
}
Also used : IPFilterRule(net.java.slee.resource.diameter.base.events.avp.IPFilterRule) Test(org.junit.Test)

Example 7 with IPFilterRule

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

the class IPFilterRuleFailTest method runTest.

@Test
public void runTest() {
    try {
        IPFilterRule r = new IPFilterRule(rule);
        Assert.assertTrue("Rule should not be parsed properly: " + r.getRuleString(), false);
    } catch (IllegalArgumentException e) {
    }
}
Also used : IPFilterRule(net.java.slee.resource.diameter.base.events.avp.IPFilterRule) Test(org.junit.Test)

Example 8 with IPFilterRule

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

the class SDPConverter method convertMediaComponents.

public static SessionDescription convertMediaComponents(MediaComponentDescription[] data, Boolean source) {
    String result = new String();
    MediaSubComponent[] currSubComponents;
    IPFilterRule[] currRules;
    Boolean rtcpFound, dataFound;
    String originAddress = new String();
    for (int i = 0; i < data.length; i++) {
        if (source && data[i].getCodecData().length > 0)
            result += data[i].getCodecData()[0] + System.getProperty("line.separator");
        else if (!source && data[i].getCodecData().length > 1)
            result += data[i].getCodecData()[1] + System.getProperty("line.separator");
        if (data[i].hasFlowStatus()) {
            switch(data[i].getFlowStatus().getValue()) {
                case FlowStatus._ENABLED_UPLINK:
                    if (source)
                        result += "a=sendonly" + System.getProperty("line.separator");
                    else
                        result += "a=recvonly" + System.getProperty("line.separator");
                    break;
                case FlowStatus._ENABLED_DOWNLINK:
                    if (source)
                        result += "a=recvonly" + System.getProperty("line.separator");
                    else
                        result += "a=sendonly" + System.getProperty("line.separator");
                    break;
                case FlowStatus._ENABLED:
                    result += "a=sendrecv" + System.getProperty("line.separator");
                    break;
                case FlowStatus._DISABLED:
                    result += "a=inactive" + System.getProperty("line.separator");
                    break;
            }
        }
        if (data[i].hasMaxRequestedBandwidthDL() && source)
            result += "b=AS:" + data[i].getMaxRequestedBandwidthDL() + System.getProperty("line.separator");
        if (data[i].hasMaxRequestedBandwidthUL() && !source)
            result += "b=AS:" + data[i].getMaxRequestedBandwidthUL() + System.getProperty("line.separator");
        if (data[i].hasRRBandwidth())
            result += "b=RR:" + data[i].getRRBandwidth() + System.getProperty("line.separator");
        if (data[i].hasRSBandwidth())
            result += "b=RS:" + data[i].getRSBandwidth() + System.getProperty("line.separator");
        currSubComponents = data[i].getMediaSubComponents();
        rtcpFound = false;
        dataFound = false;
        for (int j = 0; j < currSubComponents.length; j++) {
            if (currSubComponents[j].hasFlowUsage() && currSubComponents[j].getFlowUsage().getValue() == FlowUsage._RTCP && !rtcpFound) {
                currRules = currSubComponents[j].getFlowDescriptions();
                for (int k = 0; k < currRules.length; k++) if (currRules[k].getDirection() == IPFilterRule.DIR_IN && source) {
                    if (currRules[k].getSourcePorts().length > 0 && IPAddressUtil.isIPv4LiteralAddress(currRules[k].getSourceIp())) {
                        result += "a=rtcp:" + currRules[k].getSourcePorts()[0][0] + " IN IP4 " + currRules[k].getSourceIp() + System.getProperty("line.separator");
                        rtcpFound = true;
                    } else if (currRules[k].getSourcePorts().length > 0 && IPAddressUtil.isIPv6LiteralAddress(currRules[k].getSourceIp())) {
                        result += "a=rtcp:" + currRules[k].getSourcePorts()[0][0] + " IN IP6 " + currRules[k].getSourceIp() + System.getProperty("line.separator");
                        rtcpFound = true;
                    }
                } else if (currRules[k].getDirection() == IPFilterRule.DIR_OUT && !source) {
                    if (currRules[k].getDestPorts().length > 0 && IPAddressUtil.isIPv4LiteralAddress(currRules[k].getDestIp())) {
                        result += "a=rtcp:" + currRules[k].getDestPorts()[0][0] + " IN IP4 " + currRules[k].getDestIp() + System.getProperty("line.separator");
                        rtcpFound = true;
                    } else if (currRules[k].getDestPorts().length > 0 && IPAddressUtil.isIPv6LiteralAddress(currRules[k].getDestIp())) {
                        result += "a=rtcp:" + currRules[k].getDestPorts()[0][0] + " IN IP6 " + currRules[k].getDestIp() + System.getProperty("line.separator");
                        rtcpFound = true;
                    }
                }
            } else if (!dataFound) {
                currRules = currSubComponents[j].getFlowDescriptions();
                for (int k = 0; k < currRules.length; k++) if (currRules[k].getDirection() == IPFilterRule.DIR_IN && source) {
                    if (IPAddressUtil.isIPv4LiteralAddress(currRules[k].getSourceIp())) {
                        originAddress = "IN IP4 " + currRules[k].getSourceIp();
                        result += "c=IN IP4 " + currRules[k].getSourceIp() + System.getProperty("line.separator");
                        dataFound = true;
                    } else if (IPAddressUtil.isIPv6LiteralAddress(currRules[k].getSourceIp())) {
                        originAddress = "IN IP6 " + currRules[k].getSourceIp();
                        result += "c=IN IP6 " + currRules[k].getSourceIp() + System.getProperty("line.separator");
                        dataFound = true;
                    }
                } else if (currRules[k].getDirection() == IPFilterRule.DIR_OUT && !source) {
                    if (IPAddressUtil.isIPv4LiteralAddress(currRules[k].getDestIp())) {
                        originAddress = "IN IP4 " + currRules[k].getDestIp();
                        result += "c=IN IP4 " + currRules[k].getDestIp() + System.getProperty("line.separator");
                        dataFound = true;
                    } else if (IPAddressUtil.isIPv6LiteralAddress(currRules[k].getSourceIp())) {
                        originAddress = "IN IP6 " + currRules[k].getDestIp();
                        result += "c=IN IP6 " + currRules[k].getDestIp() + System.getProperty("line.separator");
                        dataFound = true;
                    }
                }
            }
        }
    }
    SdpFactory sdpFactory = SdpFactory.getInstance();
    try {
        // those values are not transferred in gq and are required
        result = "o=- 1 1 " + originAddress + System.getProperty("line.separator") + result;
        result = "t=0 0" + System.getProperty("line.separator") + result;
        result = "s=Diameter GQ Parser" + System.getProperty("line.separator") + result;
        result = "v=0" + System.getProperty("line.separator") + result;
        SessionDescription resultDescription = sdpFactory.createSessionDescription(result);
        return resultDescription;
    } catch (Exception ex) {
        return null;
    }
}
Also used : MediaSubComponent(net.java.slee.resource.diameter.gq.events.avp.MediaSubComponent) SessionDescription(javax.sdp.SessionDescription) IPFilterRule(net.java.slee.resource.diameter.base.events.avp.IPFilterRule) SdpFactory(javax.sdp.SdpFactory) SdpException(javax.sdp.SdpException) SdpParseException(javax.sdp.SdpParseException)

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