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" }));
}
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) {
}
}
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;
}
}
Aggregations