Skip to content

Commit

Permalink
Modified CC-CP to send ACK via Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanak Agrawal authored and Kanak Agrawal committed Apr 25, 2019
1 parent 65a7385 commit a02aac5
Show file tree
Hide file tree
Showing 9 changed files with 832 additions and 61 deletions.
11 changes: 7 additions & 4 deletions CC-CP/onos_controller/mytunnel_primary.p4
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ control c_ingress(inout headers hdr,
if(hdr.data.type_sync==WRITE_REPLY){
// Egress spec set manually for now. Can make a table of Key vs egress spec but issue
// when more WRITE packets of same key come on short time.
egressSpec_t temp = 1;
standard_metadata.egress_spec = temp;
// hdr.ipv4.dstAddr = gateway_ipaddr;
hdr.ethernet.dstAddr = gateway_mac;
standard_metadata.egress_spec = CPU_PORT;
hdr.packet_in.setValid();
hdr.packet_in.ingress_port = standard_metadata.ingress_port;
// egressSpec_t temp = 1;
// standard_metadata.egress_spec = temp;
// // hdr.ipv4.dstAddr = gateway_ipaddr;
// hdr.ethernet.dstAddr = gateway_mac;

}

Expand Down
80 changes: 72 additions & 8 deletions CC-CP/primary/MyTunnelApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,27 @@ public void process(PacketContext context) {
return;
}
}

byte[] p =((Data)final_payload).getData();
byte [] b1 = Arrays.copyOfRange(p, 0, 1); //code
byte [] b2 = Arrays.copyOfRange(p, 1, 5); //key
byte [] b3 = Arrays.copyOfRange(p, 5, 9); //value
byte [] b4 = Arrays.copyOfRange(p, 9, 10); //value
byte code = ByteBuffer.wrap(b1).get();
int type = code;

if(type == Constants.WRITE_REPLY){
MacAddress gateway_mac = MacAddress.valueOf("00:16:3e:f5:9c:b1");
MacAddress primary_mac = MacAddress.valueOf("00:16:3e:98:d2:1c");
build_response_pkt2(connectPoint,gateway_mac,primary_mac,ipv4Protocol,ipv4SourceAddress,ipv4DstAddress, udp_dstport,udp_srcport,p);
return;
}
if (!srcIPAddr.equals("192.168.100.100")) {
String payload;
if(Constants.BITWISE_DEBUG){
log.warn("payload direct = {}",((Data)final_payload).getData());
}
byte[] p =((Data)final_payload).getData();
byte [] b1 = Arrays.copyOfRange(p, 0, 1); //code
byte [] b2 = Arrays.copyOfRange(p, 1, 5); //key
byte [] b3 = Arrays.copyOfRange(p, 5, 9); //value
byte [] b4 = Arrays.copyOfRange(p, 9, 10); //value
byte code = ByteBuffer.wrap(b1).get();
int type = code;



ByteBuffer bb = ByteBuffer.wrap(((Data)final_payload).getData());
payload = new String((((Data)final_payload).getData()), Charset.forName("UTF-8"));
Expand Down Expand Up @@ -443,6 +451,62 @@ private void build_response_pkt(ConnectPoint connectPoint,MacAddress srcMac,MacA

}

private void build_response_pkt2(ConnectPoint connectPoint,MacAddress srcMac,MacAddress dstMac,byte ipv4Protocol,int ipv4SourceAddress, int ipv4DstAddress, int udp_dstport,int udp_srcport,byte[] response){
Data payload_data = new Data();
payload_data.setData(response);
UDP udp = new UDP();
udp.setSourcePort(udp_srcport);
udp.setDestinationPort(udp_dstport);
udp.setPayload(payload_data);

IPv4 ip_pkt = new IPv4();
byte ttl = 64;
ip_pkt.setDestinationAddress(ipv4DstAddress);
// ip_pkt.setDestinationAddress();
// ip_pkt.setSourceAddress(ipv4SourceAddress); // controller IP is hardcoded in Constants.java file
ip_pkt.setSourceAddress(ipv4SourceAddress); // controller IP is hardcoded in Constants.java file
ip_pkt.setProtocol(ipv4Protocol); //assuming that pacet will always be UDP
ip_pkt.setTtl(ttl);
ip_pkt.setPayload(udp);


if(Constants.DEBUG){
log.info("sending payload as = {}",response);
log.info("Sending IP header as : {}",ip_pkt);
}

Ethernet ethernet = new Ethernet();
ethernet.setEtherType(Ethernet.TYPE_IPV4)
.setDestinationMACAddress(srcMac)
.setSourceMACAddress(dstMac)
.setPayload(ip_pkt);
if(Constants.DEBUG){
log.info("1 sending payload as = {}",response);
log.info("1 Sending IP header as : {}",ip_pkt);
}

PortNumber backup_port = PortNumber.portNumber(1);

TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.setOutput(backup_port)
.build();
if(Constants.DEBUG){
log.info("2 sending payload as = {}",response);
log.info("2 Sending IP header as : {}",ip_pkt);
}
OutboundPacket outboundPacket =
new DefaultOutboundPacket(connectPoint.deviceId(), treatment,
ByteBuffer.wrap(ethernet.serialize()));
if(Constants.DEBUG) {
log.info("Processing outbound packet: {}", outboundPacket);
log.info("Ethernet packet: {}", ethernet);
}

packetService.emit(outboundPacket);

}


// Indicates whether this is a control packet, e.g. LLDP, BDDP
private boolean isControlPacket(Ethernet eth) {
short type = eth.getEtherType();
Expand Down
2 changes: 1 addition & 1 deletion CC-CP/primary/Rule_insertion.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public boolean populate_kv_store(ApplicationId appId,FlowRuleService flowRuleSer
.build();

FlowRule ins_rule = insertPiFlowRule(appId,flowRuleService,switchId, tunnelIngressTableId, match, action);
Iterable<FlowRule> rules = flowRuleService.getFlowRulesById(appId);
while(true){
Iterable<FlowRule> rules = flowRuleService.getFlowRulesById(appId);
for (FlowRule f : rules) {
Expand All @@ -89,6 +88,7 @@ public boolean populate_kv_store(ApplicationId appId,FlowRuleService flowRuleSer
}

return is_inserted;
// return true;
}


Expand Down
14 changes: 7 additions & 7 deletions CC-CP/primary/mytunnel_primary.p4
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ control c_ingress(inout headers hdr,
standard_metadata.egress_spec = hdr.packet_out.egress_port;
hdr.packet_out.setInvalid();

if(hdr.data.type_sync == WRITE){

}
return;

}
Expand All @@ -96,10 +93,13 @@ control c_ingress(inout headers hdr,
if(hdr.data.type_sync==WRITE_REPLY){
// Egress spec set manually for now. Can make a table of Key vs egress spec but issue
// when more WRITE packets of same key come on short time.
egressSpec_t temp = 1;
standard_metadata.egress_spec = temp;
// hdr.ipv4.dstAddr = gateway_ipaddr;
hdr.ethernet.dstAddr = gateway_mac;
standard_metadata.egress_spec = CPU_PORT;
hdr.packet_in.setValid();
hdr.packet_in.ingress_port = standard_metadata.ingress_port;
// egressSpec_t temp = 1;
// standard_metadata.egress_spec = temp;
// // hdr.ipv4.dstAddr = gateway_ipaddr;
// hdr.ethernet.dstAddr = gateway_mac;

}

Expand Down
28 changes: 14 additions & 14 deletions CC-CP/secondary/Rule_insertion.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ public boolean populate_kv_store(ApplicationId appId,FlowRuleService flowRuleSer
.build();

FlowRule ins_rule = insertPiFlowRule(appId,flowRuleService,switchId, tunnelIngressTableId, match, action);
Iterable<FlowRule> rules = flowRuleService.getFlowRulesById(appId);
while(true){
Iterable<FlowRule> rules = flowRuleService.getFlowRulesById(appId);
for (FlowRule f : rules) {
boolean equality = ins_rule.equals(f);
if (equality == true) {
is_inserted = true;
break;
}
}
if(is_inserted) break;
}

return is_inserted;
// while(true){
// Iterable<FlowRule> rules = flowRuleService.getFlowRulesById(appId);
// for (FlowRule f : rules) {
// boolean equality = ins_rule.equals(f);
// if (equality == true) {
// is_inserted = true;
// break;
// }
// }
// if(is_inserted) break;
// }

// return is_inserted;
return true;
}


Expand Down
27 changes: 14 additions & 13 deletions CC-sync/primary/Rule_insertion.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,20 @@ public boolean populate_kv_store(ApplicationId appId,FlowRuleService flowRuleSer
.build();

FlowRule ins_rule = insertPiFlowRule(appId,flowRuleService,switchId, tunnelIngressTableId, match, action);
while(true){
Iterable<FlowRule> rules = flowRuleService.getFlowRulesById(appId);
for (FlowRule f : rules) {
boolean equality = ins_rule.equals(f);
if (equality == true) {
is_inserted = true;
break;
}
}
if(is_inserted) break;
}

return is_inserted;
// while(true){
// Iterable<FlowRule> rules = flowRuleService.getFlowRulesById(appId);
// for (FlowRule f : rules) {
// boolean equality = ins_rule.equals(f);
// if (equality == true) {
// is_inserted = true;
// break;
// }
// }
// if(is_inserted) break;
// }

// return is_inserted;
return true;
}


Expand Down
27 changes: 14 additions & 13 deletions CC-sync/secondary/Rule_insertion.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,20 @@ public boolean populate_kv_store(ApplicationId appId,FlowRuleService flowRuleSer
.build();

FlowRule ins_rule = insertPiFlowRule(appId,flowRuleService,switchId, tunnelIngressTableId, match, action);
while(true){
Iterable<FlowRule> rules = flowRuleService.getFlowRulesById(appId);
for (FlowRule f : rules) {
boolean equality = ins_rule.equals(f);
if (equality == true) {
is_inserted = true;
break;
}
}
if(is_inserted) break;
}

return is_inserted;
// while(true){
// Iterable<FlowRule> rules = flowRuleService.getFlowRulesById(appId);
// for (FlowRule f : rules) {
// boolean equality = ins_rule.equals(f);
// if (equality == true) {
// is_inserted = true;
// break;
// }
// }
// if(is_inserted) break;
// }

// return is_inserted;
return true;
}


Expand Down
Loading

0 comments on commit a02aac5

Please sign in to comment.