Package org.midonet.client.resource

Examples of org.midonet.client.resource.BridgePort


                                  .create();
                }
            }

            // Add port on bridge
            BridgePort newPort = netBridge.addExteriorPort().create(); // returns wrapper resource of port

            // Set MidoNet port VIF ID to UUID of nic
            UUID nicUUID = getNicUUID(nic);
            newPort.vifId(nicUUID).update();
        }

        return true;
    }
View Full Code Here


    }

    private Port[] getOrCreatePublicBridgePorts(NicProfile nic, Bridge publicBridge, Router providerRouter){
        Port[] ports = new Port[2];

        BridgePort bridgeUplink = null;
        RouterPort providerDownlink = null;

        // Check if the ports and connection already exist
        for(Port peerPort : publicBridge.getPeerPorts()){
            if(peerPort != null && peerPort instanceof RouterPort){
                RouterPort checkPort = (RouterPort) peerPort;
                // Check it's a port on the providerRouter with the right gateway address
                if(checkPort.getDeviceId().compareTo(providerRouter.getId()) == 0
                        && checkPort.getPortAddress().equals(nic.getGateway())){
                    providerDownlink = checkPort;
                    bridgeUplink = (BridgePort) api.getPort(checkPort.getPeerId());
                    break;
                }
            }
        }

        // Create the ports and connection if they don't exist
        if(providerDownlink == null){
            String cidr = NetUtils.ipAndNetMaskToCidr(nic.getGateway(), nic.getNetmask());
            String cidrSubnet = NetUtils.getCidrSubNet(cidr);
            int cidrSize = (int) NetUtils.getCidrSize(NetUtils.cidr2Netmask(cidr));
            String gateway = nic.getGateway();


            // Add interior port on router side, with network details
            providerDownlink = providerRouter.addInteriorRouterPort().networkAddress(cidrSubnet).networkLength(cidrSize)
                    .portAddress(gateway).create();
            bridgeUplink = publicBridge.addInteriorPort().create();

            // Link them up
            providerDownlink.link(bridgeUplink.getId()).update();


        }

        ports[0] = bridgeUplink;
View Full Code Here

    }

    private BridgePort getBridgeToRouterPort(Network network, Bridge netBridge, Router netRouter){
        for (Port p : netBridge.getPeerPorts()) {
            if(p.getClass().equals(BridgePort.class)){
                BridgePort bp = (BridgePort) p;
                if(bp.getPeerId().compareTo(netRouter.getId()) == 0){
                    return bp;
                }
            }
        }
        return null;
View Full Code Here

        long id = getRouterId(network, isVpc);
        String routerName = getRouterName(isVpc, id);
        String accountIdStr = getAccountUuid(network);

        // Add interior port on bridge side
        BridgePort bridgePort = netBridge.addInteriorPort().create();

        // Add interior port on router side, with network details
        RouterPort routerPort = netRouter.addInteriorRouterPort();
        String cidr = network.getCidr();
        String cidrSubnet = NetUtils.getCidrSubNet(cidr);
        int cidrSize = (int) NetUtils.getCidrSize(NetUtils.cidr2Netmask(cidr));

        routerPort.networkAddress(cidrSubnet);
        routerPort.networkLength(cidrSize);
        routerPort.portAddress(network.getGateway());


        // If this is a VPC, then we will be using NetworkACLs, which is
        // implemented via chains on the router port to that network.
        if (getIsVpc(network)) {
            // Create ACL filter chain for traffic coming INTO the network
            // (outbound from the port
            int pos = 1;

            RuleChain inc = api.addChain()
                .name(getChainName(String.valueOf(network.getId()),
                                   routerName,
                                   RuleChainCode.ACL_INGRESS))
                .tenantId(accountIdStr)
                .create();


            // If it is ARP, accept it
            inc.addRule().type(DtoRule.Accept)
                         .dlType(0x0806)
                         .position(pos++)
                         .create();

            // If it is ICMP to the router, accept that
            inc.addRule().type(DtoRule.Accept)
                   .nwProto(SimpleFirewallRule.stringToProtocolNumber("icmp"))
                         .nwDstAddress(network.getGateway())
                         .nwDstLength(32)
                         .position(pos++)
                         .create();

            // If it is connection tracked, accept that as well
            inc.addRule().type(DtoRule.Accept)
                         .matchReturnFlow(true)
                         .position(pos++)
                         .create();

            inc.addRule().type(DtoRule.Drop)
                         .position(pos)
                         .create();

            //
            RuleChain out = api.addChain()
                .name(getChainName(String.valueOf(network.getId()),
                                   routerName,
                                   RuleChainCode.ACL_EGRESS))
                .tenantId(accountIdStr)
                .create();

            // Creating the first default rule here that does nothing
            // but start connection tracking.
            out.addRule().type(DtoRule.Accept)
                         .matchForwardFlow(true)
                         .position(1)
                         .create();

            routerPort.outboundFilterId(inc.getId());
            routerPort.inboundFilterId(out.getId());
        }

        routerPort.create();

        // Link them up
        bridgePort.link(routerPort.getId()).update();

        // Set up default route from router to subnet
        netRouter.addRoute().type("Normal").weight(100)
                .srcNetworkAddr("0.0.0.0").srcNetworkLength(0)
                .dstNetworkAddr(cidrSubnet).dstNetworkLength(cidrSize)
View Full Code Here

                } else if (checkPort.getType().equals("InteriorRouter")) {
                    checkPort.unlink();
                }
                checkPort.delete();
            } else if (peerPort != null && peerPort instanceof BridgePort) {
                BridgePort checkPort = (BridgePort) peerPort;
                if(checkPort.getType().equals("ExteriorBridge")) {
                    checkPort.vifId(null).update();
                } else if (checkPort.getType().equals("InteriorBridge")) {
                    checkPort.unlink();
                }
                checkPort.delete();
            }
        }

        if(tenantRouter != null){
            // Remove all peer ports if any exist
View Full Code Here

        //mockRPort
        RouterPort mockRPort = mock(RouterPort.class);
        when(mockRPort.getId()).thenReturn(UUID.fromString("550e8400-e29b-41d4-a716-446655440000"));

        //mockBPort
        BridgePort mockBPort = mock(BridgePort.class);
        when(mockBPort.link(any(UUID.class))).thenReturn(mockBPort);

        //mockPort
        Port mockPort = mock(Port.class);

        ResourceCollection<Port> peerPorts = new ResourceCollection<Port>(new ArrayList<Port>());
View Full Code Here

                        .create();
                }
            }

            // Add port on bridge
            BridgePort newPort = netBridge.addExteriorPort().create(); // returns wrapper resource of port

            // Set MidoNet port VIF ID to UUID of nic
            UUID nicUUID = getNicUUID(nic);
            newPort.vifId(nicUUID).update();
        }

        return true;
    }
View Full Code Here

    }

    private Port[] getOrCreatePublicBridgePorts(NicProfile nic, Bridge publicBridge, Router providerRouter) {
        Port[] ports = new Port[2];

        BridgePort bridgeUplink = null;
        RouterPort providerDownlink = null;

        // Check if the ports and connection already exist
        for (Port peerPort : publicBridge.getPeerPorts()) {
            if (peerPort != null && peerPort instanceof RouterPort) {
                RouterPort checkPort = (RouterPort)peerPort;
                // Check it's a port on the providerRouter with the right gateway address
                if (checkPort.getDeviceId().compareTo(providerRouter.getId()) == 0 && checkPort.getPortAddress().equals(nic.getGateway())) {
                    providerDownlink = checkPort;
                    bridgeUplink = (BridgePort)api.getPort(checkPort.getPeerId());
                    break;
                }
            }
        }

        // Create the ports and connection if they don't exist
        if (providerDownlink == null) {
            String cidr = NetUtils.ipAndNetMaskToCidr(nic.getGateway(), nic.getNetmask());
            String cidrSubnet = NetUtils.getCidrSubNet(cidr);
            int cidrSize = (int)NetUtils.getCidrSize(NetUtils.cidr2Netmask(cidr));
            String gateway = nic.getGateway();

            // Add interior port on router side, with network details
            providerDownlink = providerRouter.addInteriorRouterPort().networkAddress(cidrSubnet).networkLength(cidrSize).portAddress(gateway).create();
            bridgeUplink = publicBridge.addInteriorPort().create();

            // Link them up
            providerDownlink.link(bridgeUplink.getId()).update();

        }

        ports[0] = bridgeUplink;
        ports[1] = providerDownlink;
View Full Code Here

    }

    private BridgePort getBridgeToRouterPort(Network network, Bridge netBridge, Router netRouter) {
        for (Port p : netBridge.getPeerPorts()) {
            if (p.getClass().equals(BridgePort.class)) {
                BridgePort bp = (BridgePort)p;
                if (bp.getPeerId().compareTo(netRouter.getId()) == 0) {
                    return bp;
                }
            }
        }
        return null;
View Full Code Here

        long id = getRouterId(network, isVpc);
        String routerName = getRouterName(isVpc, id);
        String accountIdStr = getAccountUuid(network);

        // Add interior port on bridge side
        BridgePort bridgePort = netBridge.addInteriorPort().create();

        // Add interior port on router side, with network details
        RouterPort routerPort = netRouter.addInteriorRouterPort();
        String cidr = network.getCidr();
        String cidrSubnet = NetUtils.getCidrSubNet(cidr);
        int cidrSize = (int)NetUtils.getCidrSize(NetUtils.cidr2Netmask(cidr));

        routerPort.networkAddress(cidrSubnet);
        routerPort.networkLength(cidrSize);
        routerPort.portAddress(network.getGateway());

        // If this is a VPC, then we will be using NetworkACLs, which is
        // implemented via chains on the router port to that network.
        if (getIsVpc(network)) {
            // Create ACL filter chain for traffic coming INTO the network
            // (outbound from the port
            int pos = 1;

            RuleChain inc = api.addChain().name(getChainName(String.valueOf(network.getId()), routerName, RuleChainCode.ACL_INGRESS)).tenantId(accountIdStr).create();

            // If it is ARP, accept it
            inc.addRule().type(DtoRule.Accept).dlType(0x0806).position(pos++).create();

            // If it is ICMP to the router, accept that
            inc.addRule()
                .type(DtoRule.Accept)
                .nwProto(SimpleFirewallRule.stringToProtocolNumber("icmp"))
                .nwDstAddress(network.getGateway())
                .nwDstLength(32)
                .position(pos++)
                .create();

            // If it is connection tracked, accept that as well
            inc.addRule().type(DtoRule.Accept).matchReturnFlow(true).position(pos++).create();

            inc.addRule().type(DtoRule.Drop).position(pos).create();

            //
            RuleChain out = api.addChain().name(getChainName(String.valueOf(network.getId()), routerName, RuleChainCode.ACL_EGRESS)).tenantId(accountIdStr).create();

            // Creating the first default rule here that does nothing
            // but start connection tracking.
            out.addRule().type(DtoRule.Accept).matchForwardFlow(true).position(1).create();

            routerPort.outboundFilterId(inc.getId());
            routerPort.inboundFilterId(out.getId());
        }

        routerPort.create();

        // Link them up
        bridgePort.link(routerPort.getId()).update();

        // Set up default route from router to subnet
        netRouter.addRoute()
            .type("Normal")
            .weight(100)
View Full Code Here

TOP

Related Classes of org.midonet.client.resource.BridgePort

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.