本文整理汇总了Java中org.projectfloodlight.openflow.types.IpProtocol.TCP属性的典型用法代码示例。如果您正苦于以下问题:Java IpProtocol.TCP属性的具体用法?Java IpProtocol.TCP怎么用?Java IpProtocol.TCP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.projectfloodlight.openflow.types.IpProtocol
的用法示例。
在下文中一共展示了IpProtocol.TCP属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRuleDeletion
@Test
public void testRuleDeletion() throws Exception {
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.priority = 1;
firewall.addRule(rule);
int rid = rule.ruleid;
List<Map<String, Object>> rulesFromStorage = firewall.getStorageRules();
assertEquals(1, rulesFromStorage.size());
assertEquals(Integer.parseInt((String)rulesFromStorage.get(0).get("ruleid")), rid);
// delete rule
firewall.deleteRule(rid);
rulesFromStorage = firewall.getStorageRules();
assertEquals(0, rulesFromStorage.size());
}
示例2: testFirewallDisabled
@Test
public void testFirewallDisabled() throws Exception {
// firewall isn't enabled by default
// so, it shouldn't make any decision
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.priority = 1;
firewall.addRule(rule);
this.setPacketIn(tcpPacket);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
assertEquals(1, firewall.rules.size());
IRoutingDecision decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertNull(decision);
}
示例3: isTCP
@Override
public boolean isTCP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
return (ipv4.getProtocol() == IpProtocol.TCP);
}
else
{
return false;
}
}
示例4: testReadRulesFromStorage
@Test
public void testReadRulesFromStorage() throws Exception {
// add 2 rules first
FirewallRule rule = new FirewallRule();
rule.in_port = OFPort.of(2);
rule.dl_src = MacAddress.of("00:00:00:00:00:01");
rule.dl_dst = MacAddress.of("00:00:00:00:00:02");
rule.priority = 1;
rule.action = FirewallRule.FirewallAction.DROP;
firewall.addRule(rule);
rule = new FirewallRule();
rule.in_port = OFPort.of(3);
rule.dl_src = MacAddress.of("00:00:00:00:00:02");
rule.dl_dst = MacAddress.of("00:00:00:00:00:01");
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.tp_dst = TransportPort.of(80);
rule.priority = 2;
rule.action = FirewallRule.FirewallAction.ALLOW;
firewall.addRule(rule);
List<FirewallRule> rules = firewall.readRulesFromStorage();
// verify rule 1
FirewallRule r = rules.get(0);
assertEquals(r.in_port, OFPort.of(2));
assertEquals(r.priority, 1);
assertEquals(r.dl_src, MacAddress.of("00:00:00:00:00:01"));
assertEquals(r.dl_dst, MacAddress.of("00:00:00:00:00:02"));
assertEquals(r.action, FirewallRule.FirewallAction.DROP);
// verify rule 2
r = rules.get(1);
assertEquals(r.in_port, OFPort.of(3));
assertEquals(r.priority, 2);
assertEquals(r.dl_src, MacAddress.of("00:00:00:00:00:02"));
assertEquals(r.dl_dst, MacAddress.of("00:00:00:00:00:01"));
assertEquals(r.nw_proto, IpProtocol.TCP);
assertEquals(r.tp_dst, TransportPort.of(80));
assertEquals(r.any_nw_proto, false);
assertEquals(r.action, FirewallRule.FirewallAction.ALLOW);
}
示例5: testRuleInsertionIntoStorage
@Test
public void testRuleInsertionIntoStorage() throws Exception {
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.priority = 1;
firewall.addRule(rule);
List<Map<String, Object>> rulesFromStorage = firewall.getStorageRules();
assertEquals(1, rulesFromStorage.size());
assertEquals(Integer.parseInt((String)rulesFromStorage.get(0).get("ruleid")), rule.ruleid);
}
示例6: testSimpleAllowRule
@Test
public void testSimpleAllowRule() throws Exception {
// enable firewall first
firewall.enableFirewall(true);
// add TCP rule
FirewallRule rule = new FirewallRule();
rule.dl_type = EthType.IPv4;
rule.any_dl_type = false;
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
// source is IP 192.168.1.2
rule.nw_src_prefix_and_mask = IPv4AddressWithMask.of("192.168.1.2/32");
rule.any_nw_src = false;
// dest is network 192.168.1.0/24
rule.nw_dst_prefix_and_mask = IPv4AddressWithMask.of("192.168.1.0/24");
rule.any_nw_dst = false;
rule.priority = 1;
firewall.addRule(rule);
// simulate a packet-in events
this.setPacketIn(tcpPacketReply);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
IRoutingDecision decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(IRoutingDecision.RoutingAction.FORWARD_OR_FLOOD, decision.getRoutingAction());
// clear decision
IRoutingDecision.rtStore.remove(cntx, IRoutingDecision.CONTEXT_DECISION);
this.setPacketIn(tcpPacket);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(IRoutingDecision.RoutingAction.DROP, decision.getRoutingAction());
}
示例7: testLayer2Rule
@Test
public void testLayer2Rule() throws Exception {
// enable firewall first
firewall.enableFirewall(true);
// add L2 rule
FirewallRule rule = new FirewallRule();
rule.dl_src = MacAddress.of("00:44:33:22:11:00");
rule.any_dl_src = false;
rule.dl_dst = MacAddress.of("00:11:22:33:44:55");
rule.any_dl_dst = false;
rule.priority = 1;
firewall.addRule(rule);
// add TCP deny all rule
rule = new FirewallRule();
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.priority = 2;
rule.action = FirewallRule.FirewallAction.DROP;
firewall.addRule(rule);
// simulate a packet-in event
this.setPacketIn(tcpPacket);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
IRoutingDecision decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(decision.getRoutingAction(), IRoutingDecision.RoutingAction.FORWARD_OR_FLOOD);
}
示例8: processTCP
public FP_Event processTCP(FPContext cntx){
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
if (ipv4.getProtocol() == IpProtocol.TCP){
TCP tcp = (TCP) ipv4.getPayload();
short flag = tcp.getFlags();
//We assume here we have visibility of all TCP handshake messages
TCPSession session;
if (flag == 2){
session = new TCPSession(ipv4.getSourceAddress().getInt(),
tcp.getSourcePort().getPort(), ipv4.getDestinationAddress().getInt(),
tcp.getDestinationPort().getPort());
}
else{
session = new TCPSession(ipv4.getDestinationAddress().getInt(),
tcp.getDestinationPort().getPort(), ipv4.getSourceAddress().getInt(),
tcp.getSourcePort().getPort());
}
//store current TCP session into runtime context
curTCPSession.put(cntx, session);
TCPSTATE state = tcpState.get(session);
if (flag == 2){//SYN
if (state == null){
state = TCPSTATE.SYN;
session = new TCPSession(ipv4.getSourceAddress().getInt(),
tcp.getSourcePort().getPort(), ipv4.getDestinationAddress().getInt(),
tcp.getDestinationPort().getPort());
tcpState.put(session, state);
return FP_Event.TCP;
}
}
else if (flag == 16){//ACK
if (state == TCPSTATE.SYNACK){
state = TCPSTATE.ESTABLISHED;
tcpState.put(session, state);
return FP_Event.TCP_CONNECTION_SUCCESS;
}
}
else if (flag == 18){ //SYNACK
if (state == TCPSTATE.SYN){
state = TCPSTATE.SYNACK;
tcpState.put(session, state);
}
}
else if (flag == 20){//RSTACK
state = TCPSTATE.OTHERS;
tcpState.put(session, state);
return FP_Event.TCP_CONNECTION_FAIL;
}
// we consider other flags are TCP connection disruptions
// we will raise TCP connection disruption events
//TODO: More options to distinguish different TCP flags
else {
if (state != TCPSTATE.ESTABLISHED){
state = TCPSTATE.OTHERS;
tcpState.put(session, state);
return FP_Event.TCP_CONNECTION_FAIL;
}
else{//state is TCPSTATE.ESTABLISHED
if (flag == 1){ // TCP FIN
state = TCPSTATE.OTHERS;
tcpState.put(session, state);
return FP_Event.TCP_CONNECTION_FAIL;
}
}
}
return FP_Event.TCP;
}
}
return FP_Event.PACKET;
}
示例9: testOverlappingRules
@Test
public void testOverlappingRules() throws Exception {
firewall.enableFirewall(true);
// add TCP port 80 (destination only) allow rule
FirewallRule rule = new FirewallRule();
rule.dl_type = EthType.IPv4;
rule.any_dl_type = false;
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.tp_dst = TransportPort.of(80);
rule.priority = 1;
firewall.addRule(rule);
// add block all rule
rule = new FirewallRule();
rule.action = FirewallRule.FirewallAction.DROP;
rule.priority = 2;
firewall.addRule(rule);
assertEquals(2, firewall.rules.size());
// packet destined to TCP port 80 - should be allowed
this.setPacketIn(tcpPacket);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
IRoutingDecision decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(decision.getRoutingAction(), IRoutingDecision.RoutingAction.FORWARD_OR_FLOOD);
// clear decision
IRoutingDecision.rtStore.remove(cntx, IRoutingDecision.CONTEXT_DECISION);
// packet destined for port 81 - should be denied
this.setPacketIn(tcpPacketReply);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(decision.getRoutingAction(), IRoutingDecision.RoutingAction.DROP);
}