Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 33dc55b

Browse files
authored
Add files to Processus_Noir
1 parent 8b9e083 commit 33dc55b

File tree

5 files changed

+326
-0
lines changed

5 files changed

+326
-0
lines changed

‎Processus_Noir/Network.ned

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
simple Node{
2+
parameters:
3+
@display("i=block/routing");
4+
int initiator = default(1);
5+
gates:
6+
inout gate[];
7+
}
8+
9+
10+
11+
network Network {
12+
13+
types:
14+
channel Channel extends ned.DelayChannel {
15+
delay = 100 ms;
16+
}
17+
submodules:
18+
node[6] : Node;
19+
20+
connections:
21+
node[0].gate++ <--> Channel <--> node[1].gate++;
22+
node[1].gate++ <--> Channel <--> node[2].gate++;
23+
node[1].gate++ <--> Channel <--> node[4].gate++;
24+
node[3].gate++ <--> Channel <--> node[4].gate++;
25+
node[4].gate++ <--> Channel <--> node[5].gate++;
26+
27+
}

‎Processus_Noir/Processus_Noir.cc

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Processus_Noir.cc
3+
*
4+
* Created on: Y y, 2021
5+
* Author: lina
6+
*/
7+
8+
9+
#include <string.h>
10+
#include <omnetpp.h>
11+
#include "Snail_m.h"
12+
#include "Set.h"
13+
14+
using namespace omnetpp;
15+
enum{
16+
Black =7,
17+
White = 3
18+
};
19+
20+
class Node : public cSimpleModule {
21+
private:
22+
//
23+
int myIndex,
24+
my_color,
25+
num_black_node = 0;
26+
27+
bool done;
28+
29+
Set Black_nodes, // contains black node id's
30+
White_nodes, // contains white node id's
31+
Unknown; // contains the id's of unknow color's node
32+
protected:
33+
virtual void initialize() override;
34+
virtual void handleMessage(cMessage* msg) override;
35+
36+
virtual void refreshDisplay() const override;
37+
};
38+
39+
40+
Define_Module(Node);
41+
42+
void Node::initialize(){
43+
myIndex = getIndex();
44+
45+
// initialize Unknown to N(x) & Known to {x}
46+
47+
for (int i = 0; i < gateSize("gate$o"); i++) {
48+
int neighbor = gate("gate$o",i)->getPathEndGate()->getOwnerModule()->getIndex();
49+
Unknown.Add(neighbor);
50+
}
51+
52+
53+
// initialize Colors =================================
54+
if(intuniform(0, 1) == 0){
55+
my_color = Black;
56+
Black_nodes.Add(myIndex);
57+
}else{
58+
my_color = White;
59+
White_nodes.Add(myIndex);
60+
}
61+
62+
63+
// display stuff ..
64+
if(my_color == Black) {
65+
cDisplayString& dd = this->getDisplayString();
66+
dd.parse("i=block/routing,black");
67+
}
68+
69+
70+
// start the protocole ===============================
71+
for (int i = 0; i < gateSize("gate$o"); i++) {
72+
73+
// send to n
74+
Snail* msg = new Snail("MyMessage");
75+
msg->setBlackNodes(Black_nodes);
76+
msg->setWhiteNodes(White_nodes);
77+
msg->setUnknown(Unknown);
78+
79+
80+
send(msg,"gate$o",i);
81+
82+
}
83+
84+
}
85+
void Node::handleMessage(cMessage* msg){
86+
87+
Snail *smsg = check_and_cast<Snail*>(msg);
88+
Set b,w,u;
89+
90+
b = smsg->getBlackNodes();
91+
w = smsg->getWhiteNodes();
92+
u = smsg->getUnknown();
93+
94+
95+
96+
// get new colors information
97+
Black_nodes = Black_nodes.Union(b);
98+
White_nodes = White_nodes.Union(w);
99+
100+
// update unknown set
101+
Unknown = Unknown.Union(u);
102+
Unknown = Unknown.operator -(Black_nodes);
103+
Unknown = Unknown.operator -(White_nodes);
104+
105+
106+
107+
if(!done){
108+
109+
if(Unknown.Size() == 0 ) done = true;
110+
111+
// start the protocole ===============================
112+
for (int i = 0; i < gateSize("gate$o"); i++) {
113+
114+
Snail* msg = new Snail("MyMessage");
115+
msg->setBlackNodes(Black_nodes);
116+
msg->setWhiteNodes(White_nodes);
117+
msg->setUnknown(Unknown);
118+
119+
120+
send(msg,"gate$o",i);
121+
122+
}
123+
124+
}
125+
126+
num_black_node = Black_nodes.Size();
127+
}
128+
129+
void Node::refreshDisplay() const{
130+
char buf[40];
131+
sprintf(buf, "num_black_node : %d ", num_black_node);
132+
133+
getDisplayString().setTagArg("t", 0, buf);
134+
}
135+
136+
137+

‎Processus_Noir/Set.cc

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// This program is free software: you can redistribute it and/or modify
3+
// it under the terms of the GNU Lesser General Public License as published by
4+
// the Free Software Foundation, either version 3 of the License, or
5+
// (at your option) any later version.
6+
//
7+
// This program is distributed in the hope that it will be useful,
8+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
// GNU Lesser General Public License for more details.
11+
//
12+
// You should have received a copy of the GNU Lesser General Public License
13+
// along with this program. If not, see http://www.gnu.org/licenses/.
14+
//
15+
16+
#include "Set.h"
17+
#include <omnetpp.h>
18+
19+
using namespace omnetpp;
20+
Set::Set() {
21+
// TODO Auto-generated constructor stub
22+
23+
}
24+
25+
Set::~Set() {
26+
// TODO Auto-generated destructor stub
27+
}
28+
29+
void Set::Add(int i){
30+
this->content.insert(i);
31+
}
32+
33+
void Set::Remove(int i){
34+
this->content.erase(i);
35+
}
36+
37+
bool Set::Empty(){
38+
return this->content.empty();
39+
}
40+
41+
void Set::Clear(){
42+
this->content.clear();
43+
}
44+
45+
Set Set::Union(Set& s2){
46+
Set tmp;
47+
set<int, greater<int> >::iterator itr;
48+
49+
for (itr = s2.content.begin();itr != s2.content.end(); ++itr){
50+
tmp.content.insert(*itr);
51+
}
52+
53+
for (itr = content.begin();itr != content.end(); ++itr){
54+
tmp.content.insert(*itr);
55+
}
56+
57+
return tmp;
58+
}
59+
60+
void Set::Print(){
61+
set<int, greater<int> >::iterator itr;
62+
for (itr = content.begin();itr != content.end(); ++itr){
63+
EV << *itr << " ";
64+
}
65+
EV <<"\n";
66+
67+
}
68+

‎Processus_Noir/Set.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// This program is free software: you can redistribute it and/or modify
3+
// it under the terms of the GNU Lesser General Public License as published by
4+
// the Free Software Foundation, either version 3 of the License, or
5+
// (at your option) any later version.
6+
//
7+
// This program is distributed in the hope that it will be useful,
8+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
// GNU Lesser General Public License for more details.
11+
//
12+
// You should have received a copy of the GNU Lesser General Public License
13+
// along with this program. If not, see http://www.gnu.org/licenses/.
14+
//
15+
16+
#ifndef SET_H_
17+
#define SET_H_
18+
19+
20+
#include <iterator>
21+
#include <set>
22+
23+
using namespace std;
24+
25+
26+
class Set {
27+
private:
28+
set<int, greater<int> > content;
29+
30+
public:
31+
Set();
32+
virtual ~Set();
33+
void Add(int i);
34+
void Remove(int i);
35+
bool Empty();
36+
void Clear();
37+
bool Find(int i){return (content.count(i)) == 1;}
38+
Set Union(Set& s2);
39+
void Print();
40+
int Size(){
41+
int s = 0;
42+
set<int, greater<int> >::iterator itr;
43+
for (itr = this->content.begin();itr != this->content.end(); ++itr) s++;
44+
return s;
45+
46+
}
47+
Set operator + (const int & x){
48+
this->Add(x);
49+
return *this;
50+
}
51+
Set operator - (Set & A){
52+
Set tmp;
53+
set<int, greater<int> >::iterator itr;
54+
// tmp = this;
55+
for (itr = this->content.begin();itr != this->content.end(); ++itr){
56+
tmp.Add(*itr);
57+
}
58+
// tmp = tmp - A
59+
for (itr = A.content.begin();itr != A.content.end(); ++itr){
60+
tmp.Remove(*itr);
61+
}
62+
return tmp;
63+
}
64+
65+
};
66+
67+
#endif /* SET_H_ */

‎Processus_Noir/Snail.msg

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// This program is free software: you can redistribute it and/or modify
3+
// it under the terms of the GNU Lesser General Public License as published by
4+
// the Free Software Foundation, either version 3 of the License, or
5+
// (at your option) any later version.
6+
//
7+
// This program is distributed in the hope that it will be useful,
8+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
// GNU Lesser General Public License for more details.
11+
//
12+
// You should have received a copy of the GNU Lesser General Public License
13+
// along with this program. If not, see http://www.gnu.org/licenses/.
14+
//
15+
16+
17+
cplusplus {{
18+
#include "Set.h"
19+
}};
20+
21+
class noncobject Set;
22+
23+
message Snail {
24+
Set BlackNodes;
25+
Set WhiteNodes;
26+
Set Unknown;
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /