Search in sources :

Example 6 with NetworkEntity

use of nl.uva.cs.lobcder.rest.wrappers.NetworkEntity in project lobcder by skoulouzis.

the class SDNSweep method pushFlowIntoOnePort.

private void pushFlowIntoOnePort() throws IOException, ParserConfigurationException, SAXException {
    // get(0).dpid;
    String s1 = getAllSwitches().iterator().next().dpid;
    // get(1).dpid;
    String s2 = getAllSwitches().iterator().next().dpid;
    Number s1ToS2Port = 0;
    Number s2ToS1Port = 0;
    for (Link l : getAllSwitchLinks()) {
        if (l.srcSwitch.equals(s1)) {
            s1ToS2Port = l.srcPort;
            s2ToS1Port = l.dstPort;
            break;
        } else if (l.srcSwitch.equals(s2)) {
            s1ToS2Port = l.dstPort;
            s2ToS1Port = l.srcPort;
            break;
        }
    }
    List<String> s1Hosts = new ArrayList<>();
    List<String> s2Hosts = new ArrayList<>();
    for (NetworkEntity ne : getAllNetworkEntites()) {
        if (ne.getAttachmentPoint().get(0).getSwitchDPID().equals(s1)) {
            s1Hosts.add(ne.getIpv4().get(0));
        } else if (ne.getAttachmentPoint().get(0).getSwitchDPID().equals(s2)) {
            s2Hosts.add(ne.getIpv4().get(0));
        }
    }
    List<String> rules = new ArrayList<>();
    // s1 to s2
    for (String h1 : s1Hosts) {
        for (String h2 : s2Hosts) {
            String rule1To2 = "{\"switch\": \"" + s1 + "\", \"name\":\"" + h1 + "To" + h2 + "\", \"cookie\":\"0\", \"priority\":\"10\", " + "\"src-mac\":\"" + getNetworkEntitesCache().get(h1).getMac().get(0) + "\", \"ingress-port\":\"" + getNetworkEntitesCache().get(h1).getAttachmentPoint().get(0).getPort() + "\", " + "\"dst-mac\": \"" + getNetworkEntitesCache().get(h2).getMac().get(0) + "\", \"active\":\"true\"," + "\"actions\":\"output=" + s1ToS2Port + "\"}";
            rules.add(rule1To2);
        // Logger.getLogger(SDNSweep.class.getName()).log(Level.INFO, rule1To2);
        }
    }
    // s2 to s1
    for (String h1 : s2Hosts) {
        for (String h2 : s1Hosts) {
            String rule2To1 = "{\"switch\": \"" + s2 + "\", \"name\":\"" + h1 + "To" + h2 + "\", \"cookie\":\"0\", \"priority\":\"10\", " + "\"src-mac\":\"" + getNetworkEntitesCache().get(h1).getMac().get(0) + "\", \"ingress-port\":\"" + getNetworkEntitesCache().get(h1).getAttachmentPoint().get(0).getPort() + "\", " + "\"dst-mac\": \"" + getNetworkEntitesCache().get(h2).getMac().get(0) + "\", \"active\":\"true\"," + "\"actions\":\"output=" + s2ToS1Port + "\"}";
            rules.add(rule2To1);
        // Logger.getLogger(SDNSweep.class.getName()).log(Level.INFO, rule2To1);
        }
    }
    pushFlows(rules);
    flowPushed = true;
}
Also used : NetworkEntity(nl.uva.cs.lobcder.rest.wrappers.NetworkEntity) ArrayList(java.util.ArrayList) Link(nl.uva.cs.lobcder.rest.wrappers.Link)

Aggregations

ArrayList (java.util.ArrayList)6 NetworkEntity (nl.uva.cs.lobcder.rest.wrappers.NetworkEntity)6 AttachmentPoint (nl.uva.cs.lobcder.rest.wrappers.AttachmentPoint)5 Link (nl.uva.cs.lobcder.rest.wrappers.Link)4 List (java.util.List)2 WebResource (com.sun.jersey.api.client.WebResource)1 Port (nl.uva.cs.lobcder.catalogue.SDNSweep.Port)1 DefaultWeightedEdge (org.jgrapht.graph.DefaultWeightedEdge)1 NodeList (org.w3c.dom.NodeList)1