コード例 #1
0
def test_shaping():
    return TrafficControl(
        device=TrafficControlledDevice(controlledIP=test_ipaddr),
        timeout=86400,
        settings=TrafficControlSetting(down=Shaping(
            delay=Delay(delay=197, ),
            rate=81,
        ),
                                       up=Shaping(
                                           delay=Delay(delay=197, ),
                                           rate=81,
                                       )))
コード例 #2
0
    def post(self, request, service, address=None, format=None):
        ''''
        Set shaping for an IP. If address is None, defaults to
        the client IP
        @return the profile that was set on success
        '''
        # data = JSONParser().parse(request)
        data = request.DATA
        print data
        setting_serializer = SettingSerializer(data=data)
        device_serializer = DeviceSerializer(
            data=data,
            context={
                'request': request,
                'address': address
            },
        )
        if not setting_serializer.is_valid():
            raise ParseError(detail=setting_serializer.errors)

        if not device_serializer.is_valid():
            raise ParseError(detail=device_serializer.errors)

        setting = setting_serializer.save()
        device = device_serializer.save()

        tc = TrafficControl(
            device=device,
            settings=setting,
            timeout=atc_api_settings.DEFAULT_TC_TIMEOUT,
        )

        try:
            tcrc = service.startShaping(tc)
        except TrafficControlException as e:
            return Response(e.message, status=status.HTTP_401_UNAUTHORIZED)
        result = {'result': tcrc.code, 'message': tcrc.message}
        if tcrc.code:
            raise ParseError(detail=result)

        return Response(setting_serializer.data,
                        status=status.HTTP_201_CREATED)
コード例 #3
0
 def _make_tc_device(self, ip='1.1.1.1'):
     tc = TrafficControl()
     tc.device = TrafficControlledDevice(ip, ip)
     return tc
コード例 #4
0
 def _make_tc_device(self, ip='1.1.1.1'):
     tc = TrafficControl()
     tc.device = TrafficControlledDevice(ip, ip)
     return tc
コード例 #5
0
ファイル: test_secure_access.py プロジェクト: thaingoc90/NATC
    parser.add_argument('--self',
                        action='store_true',
                        help='Shape for oneself?')
    parser.add_argument('--controlling-ip',
                        default='1.1.1.1',
                        help='Controlling ip [%(default)s]')
    parser.add_argument('--controlled-ip',
                        default='2.2.2.2',
                        help='Controlled ip [%(default)s]')
    return parser.parse_args()


if __name__ == '__main__':
    options = parse_arguments()
    client = getAtcClient()
    dev = TrafficControlledDevice(controllingIP=options.controlling_ip,
                                  controlledIP=options.controlling_ip
                                  if options.self else options.controlled_ip)
    settings = TrafficControlSetting(
        up=Shaping(rate=100, ),
        down=Shaping(rate=200, ),
    )
    print settings
    tc = TrafficControl(
        device=dev,
        settings=settings,
        timeout=1000,
    )

    print client.startShaping(tc)