-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPublishSub.java
732 lines (589 loc) · 24 KB
/
PublishSub.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
package net.floodlightcontroller.publisher;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.openflow.protocol.OFFlowMod;
import org.openflow.protocol.OFFlowRemoved;
import org.openflow.protocol.OFMatch;
import org.openflow.protocol.OFMessage;
import org.openflow.protocol.OFPacketIn;
import org.openflow.protocol.OFPacketOut;
import org.openflow.protocol.OFPort;
import org.openflow.protocol.OFType;
import org.openflow.protocol.action.OFAction;
import org.openflow.protocol.action.OFActionDataLayerDestination;
import org.openflow.protocol.action.OFActionDataLayerSource;
import org.openflow.protocol.action.OFActionNetworkLayerDestination;
import org.openflow.protocol.action.OFActionNetworkLayerSource;
import org.openflow.protocol.action.OFActionOutput;
import org.openflow.util.U16;
import net.floodlightcontroller.core.FloodlightContext;
import net.floodlightcontroller.core.IOFMessageListener;
import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.core.IFloodlightProviderService;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.Set;
import net.floodlightcontroller.packet.ARP;
import net.floodlightcontroller.packet.Data;
import net.floodlightcontroller.packet.Ethernet;
import net.floodlightcontroller.packet.IPacket;
import net.floodlightcontroller.packet.IPv4;
import net.floodlightcontroller.packet.TCP;
//import org.openflow.util.HexString;
//import org.restlet.resource.ClientResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PublishSub implements IOFMessageListener, IFloodlightModule {
protected IFloodlightProviderService floodlightProvider;
protected Set<Long> macAddresses;
protected static Logger logger;
private static int lastserver;
private final static int SERVER_IP = IPv4.toIPv4Address("10.0.0.1");
private final static byte[] SERVER_MAC = Ethernet.toMACAddress("00:00:00:00:00:01");
final static Server[] SERVERS = {
new Server("10.0.0.25", "00:00:00:00:00:FE", (short)10),
new Server("10.0.0.30", "00:00:00:00:00:FF", (short)20),
new Server("10.0.0.35", "00:00:00:00:00:EE", (short)23),
};
private static short IDLE_TIMEOUT = 120; // in seconds
private static short HARD_TIMEOUT = 0; // infinite
private static int priority;
ArrayList<Host> action_pub=new ArrayList<Host>();
ArrayList<Host> action_sub=new ArrayList<Host>();
ArrayList<Host> animation_pub=new ArrayList<Host>();
ArrayList<Host> animation_sub=new ArrayList<Host>();
ArrayList<Host> contemporary_pub=new ArrayList<Host>();
ArrayList<Host> contemporary_sub=new ArrayList<Host>();
ArrayList<Host> pub = new ArrayList<Host>();
public static int iph;
public static byte[] mach;
public static short porth;
public static String type,genre,name,path;
public static String uptime;
public static short timeout=0;
Message mssg=new Message(type,genre,name,path,uptime);
@Override
public String getName() {
return "Publishers-Subscribers";
}
@Override
public boolean isCallbackOrderingPrereq(OFType type, String name) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isCallbackOrderingPostreq(OFType type, String name) {
// TODO Auto-generated method stub
return false;
}
@Override
public Collection<Class<? extends IFloodlightService>> getModuleServices() {
// TODO Auto-generated method stub
return null;
}
@Override
public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(IFloodlightProviderService.class);
return l;
}
@Override
public void init(FloodlightModuleContext context)
throws FloodlightModuleException {
floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
macAddresses = new ConcurrentSkipListSet<Long>();
logger = LoggerFactory.getLogger(Publish.class);
}
@Override
public void startUp(FloodlightModuleContext context) {
floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
//floodlightProvider.addOFMessageListener(OFType.FLOW_REMOVED, this);
}
@Override
public net.floodlightcontroller.core.IListener.Command receive(
IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
if (msg.getType() != OFType.PACKET_IN) {
// Allow the next module to also process this OpenFlow message
return Command.CONTINUE;
}
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
OFPacketIn pi = (OFPacketIn) msg;
OFMatch match = new OFMatch();
match.loadFromPacket(pi.getPacketData(), pi.getInPort());
//Destination IP Address for each packet-in
if(match.getNetworkDestination() == SERVER_IP){
if(match.getNetworkProtocol() == 17 || match.getNetworkProtocol() == 6){
logger.info("Received pub_sub request");
System.out.print("1 :: ");
System.out.println(match.loadFromPacket(pi.getPacketData(), pi.getInPort()));
int sip = match.getNetworkSource();
System.out.print("2 :: ");
byte[] smac = match.getDataLayerSource();
short sport = match.getInputPort();
// Message msg1=new Message();
Host h = new Host(sip,smac,sport);
System.out.println(IPv4.fromIPv4Address(match.getNetworkDestination()));
String s = "";
String[] ss= new String[10];
if(eth.getEtherType() == Ethernet.TYPE_IPv4){
IPv4 ip = (IPv4)eth.getPayload();
if(match.getNetworkProtocol() == 17 || match.getNetworkProtocol() == 6){
TCP tcp = (TCP)ip.getPayload();
Data data = (Data)tcp.getPayload();
byte [] bytes = data.getData();
s = new String(bytes);
ss = s.split(" ");
if(ss.length>1)
{
System.out.println("$$$$$$$$$$$ Message received is "+s);
System.out.print("type is ");
mssg.type = ss[0];
mssg.genre = ss[1];
System.out.println(mssg.type);
System.out.print("genre is ");
System.out.println(mssg.genre);
if(mssg.getType().equals("advertise") || mssg.getType().equals("publish"))
{
mssg.name = ss[2];
mssg.path = ss[3];
}
if(mssg.getType().equals("advertise"))
{
mssg.uptime = ss[4];
String a =ss[4];
System.out.println("timeout is "+mssg.getUptime());
try {
timeout= Short.parseShort(a);
} catch (NumberFormatException e) {
//Will Throw exception!
System.out.println("cannot parse!");
//do something! anything to handle the exception.
}
System.out.println("timeout is "+timeout);
}
System.out.println("genre is "+mssg.genre);
route(sw,pi,eth,h,mssg,timeout);
}
}
}
}
// System.out.println(type);
}
if (match.getDataLayerType() == Ethernet.TYPE_ARP) {
logger.info("Received an ARP request");
}
/* if(match.getTransportDestination()==80)
{
// Create a flow table modification message to add a rule
OFFlowMod rule2 = new OFFlowMod();
rule2.setType(OFType.FLOW_MOD);
rule2.setCommand(OFFlowMod.OFPFC_ADD);
System.out.println("&&&&&Reply rule&&&&");
// Create match
OFMatch replymatch = new OFMatch()
.setDataLayerDestination(match.getDataLayerDestination())
.setDataLayerSource(eth.getSourceMACAddress())
.setDataLayerType(Ethernet.TYPE_IPv4)
.setNetworkDestination(match.getNetworkDestination())
.setNetworkSource(((IPv4) eth.getPayload()).getSourceAddress())
.setTransportDestination((short)80)
.setInputPort(pi.getInPort());
// Set wildcards for Network protocol
replymatch.setWildcards(OFMatch.OFPFW_NW_PROTO);
rule2.setMatch(match);
// Specify the timeouts for the rule
rule2.setIdleTimeout(IDLE_TIMEOUT);
rule2.setHardTimeout(HARD_TIMEOUT);
// Set the buffer id to NONE -- implementation artifact
rule2.setBufferId(OFPacketOut.BUFFER_ID_NONE);
// Initialize list of actions
ArrayList<OFAction> actions = new ArrayList<OFAction>();
// Add action to re-write destination MAC to the MAC of the chosen server
OFAction rewriteMAC = new OFActionDataLayerDestination(replymatch.getDataLayerDestination());
actions.add(rewriteMAC);
// Add action to re-write destination IP to the IP of the chosen server
OFAction rewriteIP = new OFActionNetworkLayerDestination(replymatch.getNetworkDestination());
actions.add(rewriteIP);
// Add action to output packet
OFAction outputTo = new OFActionOutput(replymatch.getInputPort());
actions.add(outputTo);
// Add actions to rule
rule2.setActions(actions);
short actionsLength = (short)(OFActionDataLayerDestination.MINIMUM_LENGTH
+ OFActionNetworkLayerDestination.MINIMUM_LENGTH
+ OFActionOutput.MINIMUM_LENGTH);
// Specify the length of the rule structure
rule2.setLength((short) (OFFlowMod.MINIMUM_LENGTH + actionsLength));
logger.debug("Actions length="+ (rule2.getLength() - OFFlowMod.MINIMUM_LENGTH));
logger.debug("Install rule for forward direction for flow: " + rule2);
try {
sw.write(rule2, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
*/
return Command.CONTINUE;
}
private void flowRemove(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
// TODO Auto-generated method stub
OFMatch match;
OFFlowRemoved flRmMsg = (OFFlowRemoved) msg;
match = flRmMsg.getMatch();
int src_port = match.getTransportSource();
int dst_port = match.getTransportDestination();
int src_ip = match.getNetworkSource();
int dst_ip = match.getNetworkDestination();
byte proto = match.getNetworkProtocol();
short dl_type = match.getDataLayerType();
long bc = flRmMsg.getByteCount();
//System.out.println(flRmMsg.getPacketCount());
long t = flRmMsg.getDurationSeconds();
System.out.print("Bytes Count :"+bc+"Time is\n"+t);
double ubw =bc/t;
System.out.println("Used Bandwidth is"+ubw);
OFFlowRemoved.OFFlowRemovedReason rsn = flRmMsg.getReason();
System.out.println("Flow Removed from sw = " + sw.getId() + ", "
+ " byte counts = " + flRmMsg.getByteCount()
+ " source = " + IPv4.fromIPv4Address(src_ip) + ":" + src_port
+ " dest = " + IPv4.fromIPv4Address(dst_ip) + ":" + dst_port
+ " protocol = " + proto
+ " dl_type = " + dl_type
+ " reason = " + rsn.toString()
+ " duration = " + (flRmMsg.getDurationSeconds() + flRmMsg.getDurationNanoseconds() / 1e9)
+ " in port = " + match.getInputPort());
}
private void route(IOFSwitch sw, OFPacketIn pi, Ethernet eth,Host h,Message mssg, short timeout2) {
// TODO Auto-generated method stub
System.out.println("Hello " +mssg.getType());
if(mssg.type.equals("advertise"))
{
System.out.println("Okay!You want to advertise?");
advertise(h,mssg);//store in publishers queue
}
else if(mssg.type.equals("subscribe"))
{
System.out.println("Okay!You want to subscribe?");
subscribe(h,mssg,mssg.genre); //store in subscribers queue
}
else if(mssg.type.equals("publish"))
{
System.out.println("Okay!You want to publish?");
publish(h,mssg,sw,pi,timeout2);
}
else if(mssg.type.equals("unsubscribe"))
{
System.out.println("Okay!Unsubscribing you in a minute...");
unsubscribe(h,mssg);
}
else
{
logger.info("Invalid function.Type <advertise or publish or subscribe> <topic:action/animation/contemporary>"); //we dont care
System.out.println("Because its "+type);
}
}
private void unsubscribe(Host h, Message mssg) {
// TODO Auto-generated method stub
if(mssg.getGenre().equals("action"))
{
action_sub.remove(h);
}
else if(mssg.getGenre().equals("contemporary"))
{
contemporary_sub.remove(h);
}
else if(mssg.getGenre().equals("animation"))
{
animation_sub.remove(h);
}
else
System.out.println("Invalid format"); //the rest of the undefined topics
}
private void publish(Host h,Message mssg,IOFSwitch sw,OFPacketIn pi, short timeout2) {
// TODO Auto-generated method stub
if(mssg.getGenre().equals("action"))
{
//use action list
System.out.println("###########Action genre############");
if(action_pub!=null){
notify_sub(h,action_sub,sw,pi,mssg,timeout2);
}
else
{
System.out.println("You havn't advertised your publication yet!!");
}
}
else if(mssg.getGenre().equals("animation"))
{
if(animation_pub!=null)
notify_sub(h,animation_sub,sw,pi,mssg,timeout2);
else
System.out.println("You havn't advertised your publication yet!!");
}
else if(mssg.getGenre().equals("contemporary"))
{
//use contemporary list
if(contemporary_pub!=null)
notify_sub(h,contemporary_sub,sw,pi,mssg,timeout2);
else
System.out.println("You havn't advertised your publication yet!!");
}
}
private void notify_sub(Host h,
ArrayList<Host>sub2,IOFSwitch sw,OFPacketIn pi,Message mssg, short timeout2) {
// TODO Auto-generated method stub
Server destip= new Server("0.0.0.0","00:00:00:00:00:00",(short)0);
System.out.println("Uptime is "+mssg.getUptime());
System.out.println("timeout integer= "+timeout2);
System.out.println("notify that i have published");
if(mssg.getGenre().equals("action"))
{
System.out.println("Insert for action movies");
destip=SERVERS[0];
pub=action_pub;
System.out.println(pub.size());
}
else if(mssg.getGenre().equals("contemporary"))
{
destip=SERVERS[1];
pub=contemporary_pub;
}
else if(mssg.getGenre().equals("animation"))
{
destip=SERVERS[2];
pub=animation_pub;
}
System.out.println("number of subscribers : "+sub2.size());
if(sub2.size()>0){
for (int i = 0; i < sub2.size(); i++)
{
send_msg(i,mssg.name,mssg.path);
OFFlowMod rule = new OFFlowMod();
rule.setType(OFType.FLOW_MOD);
rule.setCommand(OFFlowMod.OFPFC_ADD);
//Host source=getNextPub();
Host dest=sub2.get(i);
System.out.println("Destination is " +mssg.getGenre() +destip +destip.getIP());
OFMatch match = new OFMatch();
match.setDataLayerDestination(dest.getMAC());
match.setDataLayerType(Ethernet.TYPE_IPv4);
match.setDataLayerSource(h.getMAC());
match.setNetworkDestination(dest.getIp());
match.setNetworkSource(h.getIp());
match.setInputPort(h.getPort());
match.setNetworkProtocol(IPv4.PROTOCOL_TCP);
System.out.println("set match proto= "+match.getNetworkProtocol());
System.out.println("set match transport port= "+match.getTransportDestination());
System.out.println("set match sip = " +match.getNetworkSource());
System.out.println("set match dip = " +match.getNetworkDestination());
//match.setWildcards(Wildcards.FULL.withNwSrcMask(24).withNwDstMask(8));
System.out.println("Hello1");
// match exact match for network destination
match.setWildcards(OFMatch.OFPFW_NW_TOS | OFMatch.OFPFW_TP_SRC | OFMatch.OFPFW_TP_DST);
// match.setWildcards(OFMatch.OFPFW_IN_PORT );
// match.setWildcards(OFMatch.OFPFW_NW_TOS);
//match.setWildcards(OFMatch.OFPFW_TP_SRC);
rule.setMatch(match);
System.out.println("Wildcards "+match.getWildcards());
priority++;
//set priority
rule.setPriority((short) priority);
// IDLE_TIMEOUT=Short.parseShort(mssg.getUptime());
//System.out.println(IDLE_TIMEOUT);
//set the timeouts for the rules
rule.setIdleTimeout(IDLE_TIMEOUT);
rule.setHardTimeout(HARD_TIMEOUT);
// Set the buffer id to NONE -- implementation artifact
rule.setBufferId(OFPacketOut.BUFFER_ID_NONE);
//Initialize list of actions
ArrayList<OFAction> actions = new ArrayList<OFAction>();
//Add action to rewrite MAC to the MAC of the chosen publisher
OFAction rewriteMAC = new OFActionDataLayerDestination(dest.getMAC());
actions.add(rewriteMAC);
// Add action to re-write destination IP to the IP of the chosen server
OFAction rewriteIP = new OFActionNetworkLayerDestination(dest.getIp());
actions.add(rewriteIP);
// Add action to output packet
OFAction outputTo = new OFActionOutput(dest.getPort());
actions.add(outputTo);
// Add actions to rule
rule.setActions(actions);
short actionsLength = (short)(OFActionDataLayerDestination.MINIMUM_LENGTH
+ OFActionNetworkLayerDestination.MINIMUM_LENGTH
+ OFActionOutput.MINIMUM_LENGTH);
// Specify the length of the rule structure
rule.setLength((short) (OFFlowMod.MINIMUM_LENGTH + actionsLength));
logger.debug("Actions length="+ (rule.getLength() - OFFlowMod.MINIMUM_LENGTH));
logger.debug("Install rule for forward direction for flow: " + rule);
try {
System.out.println("Hello2");
sw.write(rule, null);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Hello3");
push(sw, pi, actions, actionsLength);
System.out.println("%%%%%%%%%Source ip is%%%%%%%%%%% : "+match.getNetworkSource());
OFFlowMod reverseRule = new OFFlowMod();
reverseRule.setType(OFType.FLOW_MOD);
reverseRule.setCommand(OFFlowMod.OFPFC_ADD);
// Create match
OFMatch reverseMatch = new OFMatch()
.setDataLayerSource(dest.getMAC())
.setDataLayerDestination(h.getMAC())
.setDataLayerType(Ethernet.TYPE_IPv4)
.setNetworkSource(dest.getIp())
.setNetworkDestination(h.getIp())
.setNetworkProtocol(IPv4.PROTOCOL_TCP)
.setInputPort(dest.getPort());
// Set wildcards for Network protocol
reverseMatch.setWildcards(OFMatch.OFPFW_NW_TOS | OFMatch.OFPFW_TP_SRC | OFMatch.OFPFW_TP_DST);
reverseRule.setMatch(reverseMatch);
// Specify the timeouts for the rule
reverseRule.setIdleTimeout(IDLE_TIMEOUT);
reverseRule.setHardTimeout(HARD_TIMEOUT);
// Set the buffer id to NONE -- implementation artifact
reverseRule.setBufferId(OFPacketOut.BUFFER_ID_NONE);
// Initialize list of actions
ArrayList<OFAction> reverseActions = new ArrayList<OFAction>();
// Add action to re-write destination MAC to the MAC of the chosen server
OFAction reverseRewriteMAC = new OFActionDataLayerDestination(h.getMAC());
reverseActions.add(reverseRewriteMAC);
// Add action to re-write destination IP to the IP of the chosen server
OFAction reverseRewriteIP = new OFActionNetworkLayerDestination(h.getIp());
reverseActions.add(reverseRewriteIP);
// Add action to output packet
OFAction reverseOutputTo = new OFActionOutput(h.getPort());
reverseActions.add(reverseOutputTo);
// Add actions to rule
reverseRule.setActions(reverseActions);
reverseRule.setPriority((short) 2);
// Specify the length of the rule structure
reverseRule.setLength((short) (OFFlowMod.MINIMUM_LENGTH
+ OFActionDataLayerSource.MINIMUM_LENGTH
+ OFActionNetworkLayerSource.MINIMUM_LENGTH
+ OFActionOutput.MINIMUM_LENGTH));
logger.debug("Install rule for reverse direction for flow: " + reverseRule);
try {
sw.write(reverseRule, null);
} catch (Exception e) {
e.printStackTrace();
}
push(sw, pi, actions, actionsLength);
}
}
else
{
System.out.println("No subscribers for you!!");
}
}
private Host getNextPub() {
// TODO Auto-generated method stub
lastserver = (lastserver + 1) % pub.size();
return pub.get(lastserver);
//return null;
}
private void send_msg(int i, String name2, String path2) {
// TODO Auto-generated method stub
//send stats to subscribers
}
private void push(IOFSwitch sw, OFPacketIn pin,
ArrayList<OFAction> actions, short actionsLength) {
// TODO Auto-generated method stub
// create an OFPacketOut for the pushed packet
OFPacketOut po = (OFPacketOut) floodlightProvider.getOFMessageFactory()
.getMessage(OFType.PACKET_OUT);
System.out.println("Hello4");
// Update the inputPort and bufferID
po.setInPort(pin.getInPort());
po.setBufferId(pin.getBufferId());
// Set the actions to apply for this packet
po.setActions(actions);
po.setActionsLength(actionsLength);
// Set data if it is included in the packet in but buffer id is NONE
if (pin.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
byte[] packetData = pin.getPacketData();
po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
+ po.getActionsLength() + packetData.length));
po.setPacketData(packetData);
} else {
po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
+ po.getActionsLength()));
}
// Push the packet to the switch
try {
System.out.println("Hello5");
sw.write(po, null);
} catch (IOException e) {
logger.error("failed to write packetOut: ", e);
}
}
private void subscribe(Host h, Message mssg,String genre) {
// TODO Auto-generated method stub
iph=h.getIp();
mach=h.getMAC();
porth=h.getPort();
System.out.println("subscriber ip "+iph);
System.out.println("Subscriber's genre : "+mssg.getGenre());
String compare=mssg.getGenre();
System.out.println(compare);
if(genre.equals("action"))
{
System.out.println("Kya ho raha hai?");
System.out.println("Subscribers before subscription : "+action_sub.size());
action_sub.add(new Host(iph,mach,porth));
System.out.println("subscribers : "+action_sub.size());
for(int i=0;i<action_sub.size();i++)
System.out.println("Subscribers :"+action_sub.get(i));
}
else if(mssg.getGenre().equals("contemporary"))
{
contemporary_sub.add(new Host(iph,mach,porth));
}
else if(mssg.getGenre().equals("animation"))
{
animation_sub.add(new Host(iph,mach,porth));
}
else
System.out.println("Dunno!!!!It's invalid format"); //the rest of the undefined topics
}
private void advertise(Host h, Message mssg) {
// TODO Auto-generated method stub
iph=h.getIp();
mach=h.getMAC();
porth=h.getPort();
System.out.println("advertiser ip "+iph);
if(mssg.getGenre().equals("action"))
{
action_pub.add(new Host(iph,mach,porth));
System.out.println("Publishers number : "+action_pub.size());
//print the potential publishers
for(int i=0;i<action_pub.size();i++)
System.out.println("Publishers :"+action_pub.get(i));
}
else if(mssg.getGenre().equals("contemporary"))
{
contemporary_pub.add(new Host(iph,mach,porth));
}
else if(mssg.getGenre().equals("animation"))
{
animation_pub.add(new Host(iph,mach,porth));
}
else
System.out.println("Invalid format");
}
}