Skip to content

Commit 6312699

Browse files
authored
Merge pull request #567 from TomerFi/add-sip-fake-data
feature: added sip data generator.
2 parents 4fce1fa + 0bc4a58 commit 6312699

File tree

6 files changed

+464
-1
lines changed

6 files changed

+464
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Fakers
123123
* Robin
124124
* RockBand
125125
* Shakespeare
126+
* Sip
126127
* SlackEmoji
127128
* Space
128129
* StarTrek

src/main/java/com/github/javafaker/Faker.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public class Faker {
102102
private final Disease disease;
103103
private final Basketball basketball;
104104
private final Barcode barcode;
105+
private final Sip sip;
105106

106107
public Faker() {
107108
this(Locale.ENGLISH);
@@ -213,6 +214,7 @@ public Faker(FakeValuesService fakeValuesService, RandomService random) {
213214
this.disease = new Disease(this);
214215
this.basketball = new Basketball(this);
215216
this.barcode = new Barcode(this);
217+
this.sip = new Sip(this);
216218
}
217219

218220
/**
@@ -667,6 +669,8 @@ public Kaamelott kaamelott() {
667669

668670
public Barcode barcode() { return barcode; }
669671

672+
public Sip sip() { return sip; }
673+
670674
public String resolve(String key) {
671675
return this.fakeValuesService.resolve(key, this, this);
672676
}
@@ -690,4 +694,4 @@ public String resolve(String key) {
690694
public String expression(String expression) {
691695
return this.fakeValuesService.expression(expression, this);
692696
}
693-
}
697+
}
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
package com.github.javafaker;
2+
3+
import static java.nio.charset.StandardCharsets.UTF_8;
4+
5+
import java.util.ArrayList;
6+
7+
/**
8+
* Faker class for generating Session Initiation Protocol (SIP) related data.
9+
*
10+
* @author TomerFi
11+
*/
12+
public final class Sip {
13+
private final Faker faker;
14+
private final ArrayList<Integer> portPool;
15+
16+
protected Sip(final Faker faker) {
17+
this.faker = faker;
18+
int port = 40000;
19+
portPool = new ArrayList<Integer>();
20+
while (port <= 50000) {
21+
portPool.add(port);
22+
port = port + 2;
23+
}
24+
}
25+
26+
/**
27+
* The various SIP methods are listed in https://en.wikipedia.org/wiki/Session_Initiation_Protocol.
28+
*
29+
* @return a SIP method String, e.g. {@code INVITE}.
30+
*/
31+
public String method() {
32+
return faker.resolve("sip.methods");
33+
}
34+
35+
/**
36+
* Content types are based on https://tools.ietf.org/html/rfc5621 and
37+
* https://tools.ietf.org/html/rfc3261.
38+
*
39+
* @return a SIP content-type declaration String, e.g. {@code application/sdp}
40+
*/
41+
public String contentType() {
42+
return faker.resolve("sip.content.types");
43+
}
44+
45+
/**
46+
* Get a 4 digit random port for SIP messaging.
47+
*
48+
* @return a SIP messaging port int, e.g. 5060.
49+
*/
50+
public int messagingPort() {
51+
return faker.random().nextInt(1000, 9999);
52+
}
53+
54+
/**
55+
* Get a 5 digit positive even port for rtp udp communication.
56+
*
57+
* @return an RTP UDP 5 digit port int, e.g. 40002.
58+
*/
59+
public int rtpPort() {
60+
return portPool.get(faker.random().nextInt(0, portPool.size()));
61+
}
62+
63+
/**
64+
* Proviosional code, the various response codes are listed in
65+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
66+
*
67+
* @return a 3 digit SIP provisioan response code between 100 and 199 int, e.g. {@code 180}.
68+
*/
69+
public int provisionalResponseCode() {
70+
return Integer.parseInt(faker.resolve("sip.response.codes.provisional"));
71+
}
72+
73+
/**
74+
* Success code, the various response codes are listed in
75+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
76+
*
77+
* @return a 3 digit SIP success response code between 200 and 299 int, e.g. {@code 200}.
78+
*/
79+
public int successResponseCode() {
80+
return Integer.parseInt(faker.resolve("sip.response.codes.success"));
81+
}
82+
83+
/**
84+
* Redirection code, the various response codes are listed in
85+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
86+
*
87+
* @return a 3 digit SIP redirection response code between 300 and 399 int, e.g. {@code 301}.
88+
*/
89+
public int redirectResponseCode() {
90+
return Integer.parseInt(faker.resolve("sip.response.codes.redirection"));
91+
}
92+
93+
/**
94+
* Client error code, the various response codes are listed in
95+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
96+
*
97+
* @return a 3 digit SIP client error response code between 400 and 499 int, e.g. {@code 486}.
98+
*/
99+
public int clientErrorResponseCode() {
100+
return Integer.parseInt(faker.resolve("sip.response.codes.clientError"));
101+
}
102+
103+
/**
104+
* Server error code, the various response codes are listed in
105+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
106+
*
107+
* @return a 3 digit SIP server error response code between 500 and 599 int, e.g. {@code 503}.
108+
*/
109+
public int serverErrorResponseCode() {
110+
return Integer.parseInt(faker.resolve("sip.response.codes.serverError"));
111+
}
112+
113+
/**
114+
* Global error code, the various response codes are listed in
115+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
116+
*
117+
* @return a 3 digit SIP global error response code between 600 and 699 int, e.g. {@code 608}.
118+
*/
119+
public int globalErrorResponseCode() {
120+
return Integer.parseInt(faker.resolve("sip.response.codes.globalError"));
121+
}
122+
123+
/**
124+
* Proviosional phrase, the various response phrases are listed in
125+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
126+
*
127+
* @return a SIP provisional response phrase String, e.g. {@code Ringing}.
128+
*/
129+
public String provisionalResponsePhrase() {
130+
return faker.resolve("sip.response.phrases.provisional");
131+
}
132+
133+
/**
134+
* Success phrase, the various response phrases are listed in
135+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
136+
*
137+
* @return a SIP success response phrase String, e.g. {@code OK}.
138+
*/
139+
public String successResponsePhrase() {
140+
return faker.resolve("sip.response.phrases.success");
141+
}
142+
143+
/**
144+
* Redirection phrase, the various response phrases are listed in
145+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
146+
*
147+
* @return a SIP redirection response phrase String, e.g. {@code Moved Permanently}.
148+
*/
149+
public String redirectResponsePhrase() {
150+
return faker.resolve("sip.response.phrases.redirection");
151+
}
152+
153+
/**
154+
* Client error phrase, the various response phrases are listed in
155+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
156+
*
157+
* @return a SIP client error response phrase String, e.g. {@code Busy Here}.
158+
*/
159+
public String clientErrorResponsePhrase() {
160+
return faker.resolve("sip.response.phrases.clientError");
161+
}
162+
163+
/**
164+
* Server error phrase, the various response phrases are listed in
165+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
166+
*
167+
* @return a SIP server erro response phrase String, e.g. {@code Service Unavailable}.
168+
*/
169+
public String serverErrorResponsePhrase() {
170+
return faker.resolve("sip.response.phrases.serverError");
171+
}
172+
173+
/**
174+
* Server error phrase, the various response phrases are listed in
175+
* https://en.wikipedia.org/wiki/List_of_SIP_response_codes.
176+
*
177+
* @return a SIP global error response phrase String, e.g. {@code Rejected}.
178+
*/
179+
public String globalErrorResponsePhrase() {
180+
return faker.resolve("sip.response.phrases.globalError");
181+
}
182+
183+
/**
184+
* Body example of SDP type can be found in https://tools.ietf.org/html/rfc5621.
185+
*
186+
* @return a fake SDP type SIP body String.
187+
*/
188+
public String bodyString() {
189+
return "v=0\n" +
190+
"o=" + faker.name().firstName() + " " + faker.internet().uuid() + " IN IP4 " + faker.internet().domainName() + "\n" +
191+
"s=-\n" +
192+
"c=IN IP4 " + faker.internet().ipV4Address() + "\n" +
193+
"t=0 0\n" +
194+
"m=audio " + rtpPort() + " RTP/AVP 0\n" +
195+
"a=rtpmap:0 PCMU/8000";
196+
}
197+
198+
/**
199+
* Body example of SDP type can be found in https://tools.ietf.org/html/rfc5621.
200+
*
201+
* @return a fake SDP type SIP body byte array.
202+
*/
203+
public byte[] bodyBytes() {
204+
return bodyString().getBytes(UTF_8);
205+
}
206+
207+
/**
208+
* Return a valid name address to use with {@code to/from} headers.
209+
*
210+
* @return a valid name address String, e.g. {@code <sip:fakeName@10.1.2.3:5060>}.
211+
*/
212+
public String nameAddress() {
213+
return "<sip:" + faker.name().firstName() + "@" + faker.internet().ipV4Address() + ":" + messagingPort() + ">";
214+
}
215+
}

src/main/java/com/github/javafaker/service/files/EnFile.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public String getPath() {
145145
"silicon_valley.yml",
146146
"simpsons.yml",
147147
"singular_siegler.yml",
148+
"sip.yml",
148149
"slack_emoji.yml",
149150
"sonic_the_hedgehog.yml",
150151
"source.yml",

src/main/resources/en/sip.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
en:
3+
faker:
4+
sip:
5+
methods: ["INVITE", "ACK", "BYE", "CANCEL", "REGISTER", "OPTIONS", "PRACK", "SUBSCRIBE", "NOTIFY", "PUBLISH", "INFO", "REFER", "MESSAGE", "UPDATE"]
6+
content:
7+
types: [
8+
"application/sdp",
9+
"application/resource-lists",
10+
"application/pkcs7-mime",
11+
"application/pkcs7-signature",
12+
"application/x-private",
13+
"application/xml",
14+
"multipart/mixed",
15+
"multipart/alternative",
16+
"multipart/related",
17+
"text/html"]
18+
response:
19+
codes:
20+
provisional: ["100", "180", "181", "182", "183", "199"]
21+
success: ["200", "202"]
22+
redirection: ["300", "301", "302", "305", "380"]
23+
clientError: [
24+
"400",
25+
"401",
26+
"402",
27+
"403",
28+
"404",
29+
"405",
30+
"406",
31+
"407",
32+
"408",
33+
"409",
34+
"410",
35+
"413",
36+
"414",
37+
"415",
38+
"416",
39+
"420",
40+
"421",
41+
"422",
42+
"423",
43+
"480",
44+
"481",
45+
"482",
46+
"483",
47+
"484",
48+
"485",
49+
"486",
50+
"487",
51+
"488",
52+
"491",
53+
"493"]
54+
serverError: ["500", "501", "502", "503", "504", "505", "513", "555", "580"]
55+
globalError: ["600", "603", "604", "606", "607"]
56+
phrases:
57+
provisional: ["Trying", "Ringing", "Call Is Being Forwarded", "Queued", "Session Progress", "Early Dialog Terminated"]
58+
success: ["OK", "accepted"]
59+
redirection: ["Multiple Choices", "Moved Permanently", "Moved Temporarily", "Use Proxy", "Alternative Service"]
60+
clientError: [
61+
"Bad Request",
62+
"Unauthorized",
63+
"Payment Required",
64+
"Forbidden",
65+
"Not Found",
66+
"Method Not Allowed",
67+
"Not Acceptable",
68+
"Proxy Authentication Required",
69+
"Request Timeout",
70+
"Conflict",
71+
"Gone",
72+
"Request Entity Too Large",
73+
"Request-URI Too Long",
74+
"Unsupported Media Type",
75+
"Unsupported URI Scheme",
76+
"Bad Extension",
77+
"Extension Required",
78+
"Session Interval Too Small",
79+
"Interval Too Brief",
80+
"Temporarily Unavailable",
81+
"Call/Transaction Does Not Exist",
82+
"Loop Detected",
83+
"Too Many Hops",
84+
"Address Incomplete",
85+
"Ambiguous",
86+
"Busy Here",
87+
"Request Terminated",
88+
"Not Acceptable Here",
89+
"Request Pending",
90+
"Undecipherable"]
91+
serverError: [
92+
"Server Internal Error",
93+
"Not Implemented",
94+
"Bad Gateway",
95+
"Service Unavailable",
96+
"Server Time-out",
97+
"Version Not Supported",
98+
"Message Too Large",
99+
"Push Notification Service Not Supported",
100+
"Precondition Failure"]
101+
globalError: ["Busy Everywhere", "Decline", "Does Not Exist Anywhere", "Not Acceptable", "Unwanted"]

0 commit comments

Comments
 (0)